getAudioFileDuration(params: Object)

Requires:
BaseKit≥2.4.3@ray-js/ray≥0.5.9
Platforms:
iOSAndroid
import { getAudioFileDuration } from '@ray-js/ray';

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

Description

Get audio file duration information

Parameters

PropertyTypeRequiredDescription
pathstringYesAudio file path
complete() => voidNoCompletion callback (executed on both success and failure)
success(params: Object) => voidNoCallback on successful API call
fail(params: Object) => voidNoFailure callback
success callback parameters
PropertyTypeDescriptionBaseKit Since
durationnumberAudio duration in msv3.2.6
fail callback parameters
PropertyTypeDescription
errorMsgstringError message
errorCodestring | numberError code
Error extension

Return Value

None

Examples

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("Download complete, scheme path:", tempFilePath);

    getAudioFileDuration({
      path: tempFilePath,
      success: ({ duration }) => console.log("Audio duration (ms):", duration),
      fail: error => console.error("Failed to get duration:", JSON.stringify(error)),
    });
  },
  fail: error => console.error("Download failed:", JSON.stringify(error)),
});