AudioContext
The AudioContext interface inherits from BaseAudioContext.
It is responsible for supervising and managing audio-processing graph.
Constructor
constructor(options?: AudioContextOptions)
AudioContextOptions
| Parameter | Type | Default | |
|---|---|---|---|
sampleRate Optional | number | - | The preferred sample rate for the context. |
Errors
| Error type | Description |
|---|---|
NotSupportedError | sampleRate is outside the supported range [3000, 768000]. |
Properties
| Name | Type | Description | |
|---|---|---|---|
baseLatency | number | Processing latency in seconds incurred by the AudioContext passing audio from the AudioDestinationNode to the audio subsystem. Does not include hardware output latency or audio graph processing time. Equals the render callback duration (callbackFrames / sampleRate). Returns 0 when the context is not running. | Read only |
outputLatency | number | Estimated output latency in seconds — the interval between when the audio system is given a buffer and when the first sample is played by the output device. Can change when the audio route changes; re-query before sync-sensitive work. Returns 0 when the context is not running. On iOS backed by AVAudioSession.outputLatency; on Android sampled via Oboe timestamps. | Read only |
Inherits all properties from BaseAudioContext.
Methods
Inherits all methods from BaseAudioContext.
createMediaElementSource
Creates MediaElementAudioSourceNode, routing media playback into the audio graph.
| Parameter | Type | Description |
|---|---|---|
mediaElement | HTMLMediaElement (web) | AudioTagHandle (native) | Media element to route into the graph. On native, wait for onLoad on <Audio> before calling. |
Returns MediaElementAudioSourceNode.
close
Closes the audio context, releasing any system audio resources that it uses.
Returns Promise<undefined>.
suspend
Suspends time progression in the audio context. It is useful when your application will not use audio for a while.
Returns Promise<undefined>.
resume
Resumes a previously suspended audio context.