getAudioFileDuration(params: Object)

版本要求:
BaseKit≥2.4.3@ray-js/ray≥0.5.9
支持平台:
iOSAndroid
import { getAudioFileDuration } from '@ray-js/ray';

// Promise 调用
try {
  const res = await getAudioFileDuration({ ...params });
  console.log(res);
} catch (err) {
  console.log(err.errorMsg);
}

描述

获取音频文件时长信息

参数

属性类型必填说明
pathstring是音频文件路径
complete() => void否接口调用结束的回调函数(调用成功、失败都会执行)
success(params: Object) => void否接口调用成功的回调函数
fail(params: Object) => void否接口调用失败的回调函数
success 回调参数
属性类型说明BaseKit 最低版本
durationnumber音频时长, 单位 msv3.2.6
fail 回调参数
属性类型说明
errorMsgstring错误信息
errorCodestring | number错误码
错误扩展

返回值

无

示例代码

import { downloadFile, getAudioFileDuration } from '@ray-js/ray'

downloadFile({
  url: "https://airtake-public-data-1254153901.cos.ap-shanghai.myqcloud.com/ttttestfile/test-audio.m4a",
  success: ({ tempFilePath }) => {
    console.log("下载完成,协议路径:", tempFilePath);

    getAudioFileDuration({
      path: tempFilePath,
      success: ({ duration }) => console.log("音频时长(ms):", duration),
      fail: error => console.error("获取时长失败:", JSON.stringify(error)),
    });
  },
  fail: error => console.error("下载失败:", JSON.stringify(error)),
});