以Promise风格调用: 支持
获取图片信息
属性 | 类型 | 默认值 | 必填 | 说明 |
---|---|---|---|---|
src | string | 是 | 视频文件路径,可以是临时文件路径也可以是永久文件路径 | |
success | function | 否 | 接口调用成功的回调函数 | |
fail | function | 否 | 接口调用失败的回调函数 | |
complete | function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) |
属性 | 类型 | 说明 |
---|---|---|
errMsg | string | |
orientation | string | 画面方向 |
type | string | 视频格式 |
duration | number | 视频长度 |
size | number | 视频大小, 单位 kB |
height | number | 视频的长,单位 px |
width | number | 视频的宽,单位 px |
fps | number | 视频帧率 |
bitrate | number | 视频码率,单位 kbps |
合法值 | 说明 |
---|---|
up | 默认 |
down | 180度旋转 |
left | 逆时针旋转90度 |
right | 顺时针旋转90度 |
up-mirrored | 同up,但水平翻转 |
down-mirrored | 同down,但水平翻转 |
left-mirrored | 同left,但垂直翻转 |
right-mirrored | 同right,但垂直翻转 |
function getVideoInfo(src) { return new Promise((resolve, reject) => { xhs.getVideoInfo({ src, // 视频文件路径 success: (res) => resolve(res), fail: (err) => reject(err), }); }); } // 调用示例 const videoPath = '/path/to/video.mp4'; // 替换为实际的视频文件路径 getVideoInfo(videoPath) .then((res) => { console.log('视频信息获取成功:'); console.log('视频格式:', res.type); console.log('视频长度:', res.duration, '秒'); console.log('视频大小:', res.size, 'kB'); console.log('视频宽度:', res.width, 'px'); console.log('视频高度:', res.height, 'px'); console.log('视频帧率:', res.fps); console.log('视频码率:', res.bitrate, 'kbps'); console.log('画面方向:', res.orientation); }) .catch((err) => { console.error('视频信息获取失败:', err); });