---
name: "getAudioFileDuration"
mode: "kit"
versionRequirements:
  - { name: "BaseKit", version: "2.4.3" }
platform:
  - "iOS"
  - "Android"
async: true
---

## getAudioFileDuration

> [VERSION] BaseKit >= 2.4.3

> [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 | - | - | Callback invoked when the API call completes (runs on both success and failure) |
| `success` | `(params: Object) => void` ↓see below | No | - | - | Success callback of the API call |
| `fail` | `(params: Object) => void` ↓see below | No | - | - | Failure callback of the API call |

#### 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` | Extended error code |
| `errorMsg` | `string` | Extended error information |


### Examples

```tsx
ty.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);

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