# tap.chooseMedia(Object object)

以 Promise 风格调用:支持

# 功能描述

从相机拍摄或从本地相册中选择图片或视频。

# 参数

# Object object

属性类型默认值必填说明
countnumber9最多可支持20个文件
mediaTypeArray.<string>['image', 'video']文件类型
合法值说明
image只能拍摄图片或从相册选择图片
video只能拍摄视频或从相册选择视频
mix可同时选择图片和视频
sourceTypeArray.<string>['album', 'camera']图片和视频选择的来源
合法值说明
album从相册选择
camera使用相机拍摄
maxDurationnumber10拍摄视频最长拍摄时间,单位秒。时间范围为 3s 至 60s 之间。不限制相册。安卓不支持该参数,设置无效
sizeTypeArray.<string>['compressed']是否压缩所选文件, iOS对所有mediaType生效 不支持original,设置任何值只返回压缩过的图片和视频
camerastring'back'仅在 sourceType 为 camera 时生效,使用前置或后置摄像头。安卓只支持back,设置front无效
合法值说明
back使用后置摄像头
front使用前置摄像头
successfunction接口调用成功的回调函数
failfunction接口调用失败的回调函数
completefunction接口调用结束的回调函数(调用成功、失败都会执行)

# object.success 回调函数

# 参数
# Object res
属性类型说明
tempFilesArray.<Object>本地临时文件列表
结构属性类型说明
tempFilePathstring本地临时文件路径 (本地路径)
sizenumber本地临时文件大小,单位 B
durationnumber视频的时间长度
heightnumber视频的高度
widthnumber视频的宽度
thumbTempFilePathstring视频缩略图临时文件路径
fileTypestring文件类型
合法值说明
image图片
video视频
typestring文件类型,有效值有 image 、video、mix

# 示例代码

tap.chooseMedia({
  count: 9,
  mediaType: ['image','video'],
  sourceType: ['album', 'camera'],
  maxDuration: 30,
  camera: 'back',
  success(res) {
    console.log(res.tempFiles[0].tempFilePath)
    console.log(res.tempFiles[0].size)
  }
})