React Native · APIs and utilities
Audio
Audio API.
10 exports
Import
Audio
moduleAudio API.
| Name | Type | Description |
|---|---|---|
createPlayer | (source: AudioSource, options?: AudioPlayerOptions) => AudioPlayer | Creates a player. |
startRecording | (options?: RecordAudioOptions) => Promise<void> | Starts recording (requires microphone permission). |
stopRecording | () => Promise<AudioRecording | null> | Stops recording; null if there is no recording. |
isRecording | () => boolean | Is recording in progress. |
onRecordingStatus | (listener: (status: { duration: number; level: number; }) => void) => () => void | Duration and level during recording (with metering: true). |
AudioPlayer
classAn audio player. Call release() when done (or use useAudioPlayer; it releases when the component unmounts).
useAudioPlayer
functionPlayer bound to a component: reloads when the source changes and is released when the component unmounts. Re-renders on every status change.
useAudioRecorder
functionRecording with recording state. If recording when the component unmounts, it is stopped.
AudioStatus
interfacePlayer status.
| Name | Type | Description |
|---|---|---|
position | number | Position (seconds). |
duration | number | Duration (seconds); 0 if unknown (live stream). |
playing | boolean | Is it playing. |
loaded | boolean | Is it loaded. |
AudioSource
typeAudio source: a URL (file://, https://) or require("./sound.mp3").
AudioPlayerOptions
interfacePlayer settings.
| Name | Type | Default | Description |
|---|---|---|---|
loop? | boolean | false | Restart from the beginning at the end. |
volume? | number | 1 | Volume (0–1). |
rate? | number | 1 | Rate (0.5–2). |
AudioRecording
interfaceA recorded sound.
| Name | Type | Description |
|---|---|---|
uri | string | Temporary file (file://…m4a). |
duration | number | Duration (seconds). |
RecordAudioOptions
interfaceRecording options.
| Name | Type | Default | Description |
|---|---|---|---|
quality? | "high" | "low" | "high" | high: 44.1 kHz 128 kbps; low: 22 kHz 48 kbps (speech). |
metering? | boolean | false | Level events (level in onStatus, dBFS −160…0). |
UseAudioRecorderResult
interfaceResult of useAudioRecorder.
| Name | Type | Description |
|---|---|---|
recording | boolean | Is recording in progress. |
duration | number | Duration (seconds; live with metering). |
level | number | Level (dBFS; with metering). |
start | () => Promise<void> | Start. |
stop | () => Promise<AudioRecording | null> | Stop; returns the recording. |