以Promise风格调用: 支持
拍摄视频或从手机相册中选视频。
属性 | 类型 | 默认值 | 必填 | 说明 |
---|---|---|---|---|
sourceType | array | album,camera | 否 | 指定视频来源为相册(album)或相机(camera) ,默认两者都有 |
compressed | boolean | true | 否 | 是否需要压缩视频源文件,默认值为 true,需要压缩 |
camera | string | back, front | 否 | 默认拉起的是前置或者后置摄像头 |
maxDuration | number | 60 | 否 | 选择视频的最大时长(单位:s) |
success | function | 否 | 接口调用成功的回调函数 | |
fail | function | 否 | 接口调用失败的回调函数 | |
complete | function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) |
属性 | 类型 | 说明 |
---|---|---|
tempFilePath | string | 选定视频的临时文件路径 |
duration | number | 选定视频的时间长度 (单位:s) |
size | number | 选定视频的数据量大小(单位:B) |
width | number | 选定视频的视频宽度(单位:px) |
height | number | 选定视频的高度(单位:px) |
errMsg | string |
function chooseVideo(options = {}) { return new Promise((resolve, reject) => { xhs.chooseVideo({ ...options, success: (res) => resolve(res), fail: (err) => reject(err), }); }); } // 调用示例 chooseVideo({ sourceType: ['album', 'camera'], // 指定来源 compressed: true, // 是否压缩 camera: 'back', // 默认后置摄像头 maxDuration: 30, // 最大时长 30 秒 }) .then((res) => { console.log('视频选择成功:', res); // 处理返回结果 console.log('临时文件路径:', res.tempFilePath); console.log('视频时长:', res.duration); console.log('视频大小:', res.size); console.log('视频宽度:', res.width); console.log('视频高度:', res.height); }) .catch((err) => { console.error('视频选择失败:', err); });