AudioPlaybackStreamBuilder
Constructors
new AudioPlaybackStreamBuilder()
new AudioPlaybackStreamBuilder():
AudioPlaybackStreamBuilder
Returns
Properties
args
args:
Object
={}
Methods
buildAsync()
buildAsync():
Promise
<AudioPlaybackStream
>
Creates a new AudioPlaybackStream using the current builder configuration. Must call setAudioConfig and setAudioAttributes before building.
Returns
Promise
<AudioPlaybackStream
>
A promise that resolves to:
- New AudioPlaybackStream instance if successful
Or rejects with:
STATUS_BAD_VALUE (-2)
: Missing required configurationSTATUS_NO_INIT (-3)
: Audio system not initializedSTATUS_NO_MEMORY (-1)
: Failed to allocate resourcesSTATUS_DEAD_OBJECT (-5)
: Server communication errorSTATUS_INVALID_OPERATION (-8)
: Invalid configuration combination
reset()
reset():
void
Resets all builder configuration to default values.
Use this to reuse the builder for creating a different stream configuration.
Returns
void
setAudioAttributes()
setAudioAttributes(
attributes
):void
Sets the audio attributes for the stream to be built. This must be called before buildAsync. These attributes affect how the stream interacts with the audio focus system.
Parameters
attributes
Audio attributes object containing:
- contentType: Type of content from types/AudioCoreClientTypes.AudioContentType enum
- usage: Usage scenario from types/AudioCoreClientTypes.AudioUsageType enum
- flags: Behavior flags from types/AudioCoreClientTypes.AudioFlags enum
Returns
void
setAudioConfig()
setAudioConfig(
config
):void
Sets the audio configuration for the stream to be built. This must be called before buildAsync.
Parameters
config
Audio configuration object containing:
sampleRate
: Sample rate in Hz from types/AudioCoreClientTypes.AudioSampleRate enumchannelMask
: Channel configuration from types/AudioCoreClientTypes.AudioChannelMask enumformat
: Sample format from types/AudioCoreClientTypes.AudioSampleFormat enum
Returns
void
setAudioEffectSessionId()
setAudioEffectSessionId(
effectSessionId
):void
Sets custom audio effect session ID for the stream. This allows applying custom audio effects to this stream.
Parameters
effectSessionId
number
Effect session ID obtained from: AudioManager.AudioManager.allocateCustomAudioEffectSessionAsync
Returns
void
setAudioFocusSessionId()
setAudioFocusSessionId(
focusSessionId
):void
Sets the audio focus session ID for the stream. This associates the stream with a specific focus session for focus management.
Parameters
focusSessionId
number
Focus session ID obtained from:
- AudioFocusManager.AudioFocusManager.createAudioFocusSessionAsync
- AudioFocusManager.AudioFocusManager.getDefaultAudioFocusSessionAsync
- An existing AudioFocusSession.AudioFocusSession.getAudioSessionId
Returns
void
setBufferCount()
setBufferCount(
bufferCount
):void
Sets the number of buffers to use for the stream. More buffers increase latency but provide better protection against underruns.
Parameters
bufferCount
number
Number of buffers. Must be greater than 0. Typical values: 2, 3, 4
Returns
void
setDuckingPolicy()
setDuckingPolicy(
duckPolicy
):void
Sets the ducking policy for the stream. This determines how volume reduction is handled when audio focus is ducked.
Parameters
duckPolicy
The ducking policy:
SYSTEM (0)
: System handles volume reduction automaticallyEXPLICIT (1)
: Application must handle volume reduction using AudioPlaybackStream.duckVolumeAsync calls
Returns
void
setFramesPerBuffer()
setFramesPerBuffer(
framesPerBuffer
):void
Sets the number of frames per buffer for the stream. Larger values increase latency but improve power efficiency. Smaller values decrease latency but may cause underruns.
Parameters
framesPerBuffer
number
Number of frames per buffer. Must be greater than 0. Typical values: 256, 512, 1024, 2048
Returns
void
setUnderrunThreshold()
setUnderrunThreshold(
framesThreshold
):void
Sets the threshold for reporting buffer underruns. An underrun occurs when the playback buffer becomes empty.
Parameters
framesThreshold
number
Number of frames threshold. When available frames drops below this value, an underrun event will be triggered. Must be greater than 0.
Returns
void
destroyAsync()
static
destroyAsync(playbackStream
):Promise
<AudioStatus
>
Destroys an existing AudioPlaybackStream. This releases all resources associated with the stream. The stream object Must not be used after calling this method. Any ongoing playback will be stopped.
Parameters
playbackStream
The stream to destroy
Returns
Promise
<AudioStatus
>
A promise that resolves to:
STATUS_NO_ERROR (0)
: Stream destroyed successfullySTATUS_BAD_VALUE (-2)
: Invalid stream objectSTATUS_NO_INIT (-3)
: Audio system not initializedSTATUS_INVALID_OPERATION (-8)
: Stream already destroyed
Last updated: Sep 30, 2025