基础库 2.10.0 开始支持,低版本需做兼容处理。
拍摄或从手机相册中选择图片或视频。
| 属性 | 类型 | 默认值 | 必填 | 说明 |
|---|---|---|---|---|
| count | number | 9 | 否 | 最多可以选择的文件个数 |
| mediaType | Array.<string> | ['image', 'video'] | 否 | 文件类型 |
| sourceType | Array.<string> | ['album', 'camera'] | 否 | 图片和视频选择的来源 |
| maxDuration | number | 10 | 否 | 拍摄视频最长拍摄时间,单位秒。时间范围为 3s 至 30s 之间 |
| sizeType | Array.<string> | ['original', 'compressed'] | 否 | 仅对 mediaType 为 image 时有效,是否压缩所选文件 |
| camera | string | 'back' | 否 | 仅在 sourceType 为 camera 时生效,使用前置或后置摄像头 |
| success | function | 否 | 接口调用成功的回调函数 | |
| fail | function | 否 | 接口调用失败的回调函数 | |
| complete | function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) |
object.mediaType 的合法值
| 值 | 说明 | 最低版本 |
|---|---|---|
| image | 只能拍摄图片或从相册选择图片 | |
| video | 只能拍摄视频或从相册选择视频 |
object.sourceType 的合法值
| 值 | 说明 | 最低版本 |
|---|---|---|
| album | 从相册选择 | |
| camera | 使用相机拍摄 |
object.camera 的合法值
| 值 | 说明 | 最低版本 |
|---|---|---|
| back | 使用后置摄像头 | |
| front | 使用前置摄像头 |
| 属性 | 类型 | 说明 |
|---|---|---|
| tempFiles | Array.<Object> | 本地临时文件列表 |
| type | string | 文件类型,有效值有 image 、video |
res.tempFiles 的结构
| 属性 | 类型 | 说明 |
|---|---|---|
| tempFilePath | string | 本地临时文件路径 (本地路径) |
| size | number | 本地临时文件大小,单位 B |
| duration | number | 视频的时间长度 |
| height | number | 视频的高度 |
| width | number | 视频的宽度 |
| thumbTempFilePath | string | 视频缩略图临时文件路径 |
wx.chooseMedia({
count: 9,
mediaType: ['image','video'],
sourceType: ['album', 'camera'],
maxDuration: 30,
camera: 'back',
success(res) {
console.log(res.tempFiles.tempFilePath)
console.log(res.tempFiles.size)
}
}) 备案信息: 粤ICP备15087711号-2
Copyright © 2008-2025 啊嘎哇在线工具箱 All Rights.
本站所有资料来源于网络,版权归原作者所有,仅作学习交流使用,如不慎侵犯了您的权利,请联系我们。