-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
df60196
commit 524c760
Showing
3 changed files
with
175 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
--- | ||
title: Taro.chooseMedia(option) | ||
sidebar_label: chooseMedia | ||
--- | ||
|
||
> 最低 Taro 版本: 2.10.0 | ||
拍摄或从手机相册中选择图片或视频。 | ||
|
||
> [参考文档](https://developers.weixin.qq.com/miniprogram/dev/api/media/video/wx.chooseMedia.html) | ||
## 类型 | ||
|
||
```tsx | ||
(option: Option) => Promise<SuccessCallbackResult> | ||
``` | ||
|
||
## 参数 | ||
|
||
### Option | ||
|
||
| 参数 | 类型 | 必填 | 说明 | | ||
| --- | --- | :---: | --- | | ||
| count | `number` | 否 | 最多可以选择的文件个数 | | ||
| mediaType | ("video" or "image")[] | 否 | 文件类型 | | ||
| sourceType | ("album" or "camera")[] | 否 | 图片和视频选择的来源 | | ||
| maxDuration | `number` | 否 | 拍摄视频最长拍摄时间,单位秒。时间范围为 3s 至 30s 之间 | | ||
| sizeType | ("original" or "compressed")[] | 否 | 仅对 mediaType 为 image 时有效,是否压缩所选文件 | | ||
| camera | `string` | 否 | 仅在 sourceType 为 camera 时生效,使用前置或后置摄像头 | | ||
| fail | `(res: CallbackResult) => void` | 否 | 接口调用失败的回调函数 | | ||
| success | `(result: SuccessCallbackResult) => void` | 否 | 接口调用成功的回调函数 | | ||
|
||
### SuccessCallbackResult | ||
|
||
| 参数 | 类型 | 说明 | | ||
| --- | --- | --- | | ||
| tempFiles | `ChooseMedia[]` | 本地临时文件列表 | | ||
| type | `string` | 文件类型,有效值有 image 、video | | ||
|
||
### ChooseMedia | ||
|
||
本地临时文件列表 | ||
|
||
| 参数 | 类型 | 说明 | | ||
| --- | --- | --- | | ||
| tempFilePath | `string` | 本地临时文件路径 (本地路径) | | ||
| size | `number` | 本地临时文件大小,单位 B | | ||
| duration | `number` | 视频的时间长度 | | ||
| height | `number` | 视频的高度 | | ||
| width | `number` | 视频的宽度 | | ||
| thumbTempFilePath | `string` | 视频缩略图临时文件路径 | | ||
|
||
### mediaType | ||
|
||
| 参数 | 说明 | | ||
| --- | --- | | ||
| video | 只能拍摄视频或从相册选择视频 | | ||
| image | 只能拍摄图片或从相册选择图片 | | ||
|
||
### sourceType | ||
|
||
| 参数 | 说明 | | ||
| --- | --- | | ||
| album | 从相册选择 | | ||
| camera | 使用相机拍摄 | | ||
|
||
### camera | ||
|
||
| 参数 | 说明 | | ||
| --- | --- | | ||
| back | 使用后置摄像头 | | ||
| front | 使用前置摄像头 | | ||
|
||
## 示例代码 | ||
|
||
```tsx | ||
wx.chooseMedia({ | ||
count: 9, | ||
mediaType: ['image','video'], | ||
sourceType: ['album', 'camera'], | ||
maxDuration: 30, | ||
camera: 'back', | ||
success(res) { | ||
console.log(res.tempFiles) | ||
console.log(res.type) | ||
} | ||
}) | ||
``` | ||
|
||
## API 支持度 | ||
|
||
| API | 微信小程序 | H5 | React Native | | ||
| :---: | :---: | :---: | :---: | | ||
| Taro.chooseMedia | ✔️ | | | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters