---
name: "getAudioFileDuration"
mode: "kit"
versionRequirements:
  - { name: "BaseKit", version: "2.4.3" }
  - { name: "@ray-js/ray", version: "0.5.9" }
platform:
  - "iOS"
  - "Android"
async: true
---

## getAudioFileDuration

> [VERSION] BaseKit >= 2.4.3 | @ray-js/ray >= 0.5.9

> [PLATFORM] iOS, Android

> ⚡ **Supports Promise** — Returns a Promise when success / fail / complete callbacks are omitted.

### Description

Get audio file duration information

### Parameters

| Property | Type | Required | Default | Since | Description |
| --- | --- | --- | --- | --- | --- |
| `path` | `string` | Yes | - | `2.4.3` | Audio file path |
| `complete` | `() => void` | No | - | - | Completion callback (executed on both success and failure) |
| `success` | `(params: Object) => void` ↓see below | No | - | - | Callback on successful API call |
| `fail` | `(params: Object) => void` ↓see below | No | - | - | Failure callback |

#### success callback parameters

| Property | Type | Since | Description |
| --- | --- | --- | --- |
| `duration` | `number` | `3.2.6` | Audio duration in ms |

#### fail callback parameters

| Property | Type | Description |
| --- | --- | --- |
| `errorMsg` | `string` | Error message |
| `errorCode` | `string \| number` | Error code |
| `innerError` | `Object` | Error extension |

##### fail(params).innerError properties

| Property | Type | Description |
| --- | --- | --- |
| `errorCode` | `string \| number` | Error extension code |
| `errorMsg` | `string` | Error extension message |


### Examples

#### Demo

```tsx
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)),
});
```
