AudioPlaybackStream
Constructors
new AudioPlaybackStream()
new AudioPlaybackStream(
id):AudioPlaybackStream
Creates a new AudioPlaybackStream instance. This constructor must not be called directly. Use AudioPlaybackStreamBuilder.AudioPlaybackStreamBuilder.buildAsync to create instances.
Parameters
id
number
Internal stream identifier
Returns
Properties
streamId
streamId:
number
Methods
duckVolumeAsync()
duckVolumeAsync(
mode,value,rampDurationMs):Promise<number>
Adjusts the volume of the stream for ducking purposes. Only effective when using EXPLICIT ducking policy.
Parameters
mode
number
DB (0) or PERCENTAGE (1)
value
number
Amount to reduce volume:
- For
DB: 0-144 dB reduction - For
PERCENTAGE: 0-100% reduction
rampDurationMs
number
Time in milliseconds to reach target volume
Returns
Promise<number>
A promise that resolves to:
STATUS_NO_ERROR (0): Volume ducked successfullySTATUS_NO_INIT (-3): Stream not initializedSTATUS_BAD_VALUE (-2): Invalid parametersSTATUS_INVALID_OPERATION (-8): Wrong ducking policy
flushAsync()
flushAsync():
Promise<AudioStatus>
Flushes all buffered data without changing the playback state.
Returns
Promise<AudioStatus>
A promise that resolves to:
STATUS_NO_ERROR (0): Successfully flushedSTATUS_NO_INIT (-3): Stream not initializedSTATUS_INVALID_OPERATION (-8): Cannot flush while playingSTATUS_DEAD_OBJECT (-5): Server communication error
getAudioAttributesAsync()
getAudioAttributesAsync():
Promise<AudioAttributes>
Retrieves the current audio attributes of the playback stream.
Returns
Promise<AudioAttributes>
A promise that resolves to an AudioAttributes object containing:
contentType: Type of content being playedusage: Usage category of the streamflags: Current behavior flags Or rejects with:STATUS_NO_INIT (-3): Stream not initializedSTATUS_DEAD_OBJECT (-5): Server communication error
getAudioConfigAsync()
getAudioConfigAsync():
Promise<AudioConfig>
Retrieves the current audio configuration of the playback stream.
Returns
Promise<AudioConfig>
A promise that resolves to an AudioConfig object containing:
sampleRate: Current sample rate in HzchannelMask: Current channel configurationformat: Current sample format Or rejects with:STATUS_NO_INIT (-3): Stream not initializedSTATUS_DEAD_OBJECT (-5): Server communication error
getAudioEffectSessionIdAsync()
getAudioEffectSessionIdAsync():
Promise<number>
Gets the custom audio effect session ID associated with this stream.
Returns
Promise<number>
A promise that resolves to:
- Positive value: The effect session ID
STATUS_NO_INIT (-3): Stream not initializedSTATUS_BAD_VALUE (-2): No effect session assigned
getAudioFocusSessionIdAsync()
getAudioFocusSessionIdAsync():
Promise<number>
Gets the audio focus session ID associated with this stream.
Returns
Promise<number>
A promise that resolves to:
- Positive value: The focus session ID
STATUS_NO_INIT (-3): Stream not initializedSTATUS_BAD_VALUE (-2): No focus session assigned
getBufferCountAsync()
getBufferCountAsync():
Promise<number>
Gets the number of buffers configured for this stream.
Returns
Promise<number>
A promise that resolves to:
- Positive value: Number of buffers
STATUS_NO_INIT (-3): Stream not initializedSTATUS_DEAD_OBJECT (-5): Server communication error
getChannelCountAsync()
getChannelCountAsync():
Promise<number>
Gets the channel count of the playback stream.
Returns
Promise<number>
A promise that resolves to:
- Positive value: Number of channels
STATUS_NO_INIT (-3): Stream not initializedSTATUS_DEAD_OBJECT (-5): Server communication error
getDuckingPolicyAsync()
getDuckingPolicyAsync():
Promise<number>
Gets the current ducking policy of the stream.
Returns
Promise<number>
A promise that resolves to types/AudioCoreClientTypes.StreamDuckingPolicy:
SYSTEM (0): System handles duckicking automaticallyEXPLICIT (1): Application must handle ducking
Or rejects with:
STATUS_NO_INIT (-3): Stream not initializedSTATUS_DEAD_OBJECT (-5): Server communication error
getFramesPerBufferAsync()
getFramesPerBufferAsync():
Promise<number>
Gets the number of frames per buffer configured for this stream.
Returns
Promise<number>
A promise that resolves to:
- Positive value: Frames per buffer
STATUS_NO_INIT (-3): Stream not initializedSTATUS_DEAD_OBJECT (-5): Server communication error
getLatencyInMsAsync()
getLatencyInMsAsync():
Promise<number>
Gets the current latency of the playback stream in milliseconds. This includes both buffer and hardware latency.
Returns
Promise<number>
A promise that resolves to:
- Positive value: Latency in milliseconds
STATUS_NO_INIT (-3): Stream not initializedSTATUS_DEAD_OBJECT (-5): Server communication error
getNumBytesInPipelineAsync()
getNumBytesInPipelineAsync():
Promise<number>
Gets the number of bytes currently in the playback pipeline waiting to be played.
Returns
Promise<number>
A promise that resolves to:
- Positive value: Number of bytes in pipeline
STATUS_NO_INIT (-3): Stream not initializedSTATUS_DEAD_OBJECT (-5): Server communication error
getNumBytesOfNativeBufferAsync()
getNumBytesOfNativeBufferAsync():
Promise<number>
Gets the size of the native buffer used for playback. This represents the maximum amount of data that can be queued for playback.
Returns
Promise<number>
A promise that resolves to:
- Positive value: Buffer size in bytes
STATUS_NO_INIT (-3): Stream not initializedSTATUS_DEAD_OBJECT (-5): Server communication error
getPresentedFrameCountAsync()
getPresentedFrameCountAsync():
Promise<number>
Gets the total number of frames that have been played.
Returns
Promise<number>
A promise that resolves to:
- Positive value: Number of frames played to audio pipeline on success.
STATUS_NO_INIT (-3): Stream not initializedSTATUS_DEAD_OBJECT (-5): Server communication error
getSampleRateAsync()
getSampleRateAsync():
Promise<number>
Gets the sample rate of the playback stream.
Returns
Promise<number>
A promise that resolves to:
- Positive value: Sample rate in Hz
STATUS_NO_INIT (-3): Stream not initializedSTATUS_DEAD_OBJECT (-5): Server communication error
getSampleSizeAsync()
getSampleSizeAsync():
Promise<number>
Gets the sample size in bits of the playback stream.
Returns
Promise<number>
A promise that resolves to:
- Positive value: Sample size in bits (e.g., 16, 24, 32)
STATUS_NO_INIT (-3): Stream not initializedSTATUS_DEAD_OBJECT (-5): Server communication error
getUnderrunCountAsync()
getUnderrunCountAsync():
Promise<number>
Gets the total number of underrun occurrences.
Returns
Promise<number>
A promise that resolves to:
-
Positive value: Number of underrun occurrences during stream lifetime.
STATUS_NO_INIT (-3): Stream not initializedSTATUS_DEAD_OBJECT (-5): Server communication error
getUnderrunSizeAsync()
getUnderrunSizeAsync():
Promise<number>
Gets the underrun size in frames. An underrun occurs when the playback buffer becomes empty.
Returns
Promise<number>
A promise that resolves to:
- Positive value: Difference in frames between buffer size and underrun threshold. Frame value is rounded up.
-
0: No underrun STATUS_NO_INIT (-3): Stream not initializedSTATUS_DEAD_OBJECT (-5): Server communication error
getVolumeAsync()
getVolumeAsync():
Promise<number>
Gets the stream's current volume level.
Returns
Promise<number>
A promise that resolves to:
- 0-100: Current volume level
STATUS_NO_INIT (-3): Stream not initializedSTATUS_DEAD_OBJECT (-5): Server communication error
initCheckAsync()
initCheckAsync():
Promise<AudioStatus>
Verifies if the playback stream has been properly initialized. Must be called before using other methods to ensure the stream is ready.
Returns
Promise<AudioStatus>
A promise that resolves to:
STATUS_NO_ERROR (0): Stream is properly initializedSTATUS_NO_INIT (-3): Stream not initializedSTATUS_DEAD_OBJECT (-5): Server communication error
pauseAsync()
pauseAsync():
Promise<AudioStatus>
Pauses playback of the stream. Data in the buffer is retained and playback can be resumed with startAsync.
Returns
Promise<AudioStatus>
A promise that resolves to:
STATUS_NO_ERROR (0): Successfully pausedSTATUS_NO_INIT (-3): Stream not initializedSTATUS_INVALID_OPERATION (-8): Stream already pausedSTATUS_DEAD_OBJECT (-5): Server communication error
queryMinimumBufferInfoAsync()
queryMinimumBufferInfoAsync():
Promise<Object>
Get minimum buffer information
Returns
Promise<Object>
object with fields minFramesPerBuffer and minBufferCount
registerEventObserverAsync()
registerEventObserverAsync(
callback):Promise<AudioStatus>
Registers a callback to receive playback stream events. Only one callback can be registered at a time.
Parameters
callback
(value) => void
Function to receive events. Events include:
DIED (0): Stream has failedRECOVERED (1): Stream has recovered from failureSTOPPED (2): Playback has stoppedMUTE_STATE_UPDATE (3): Stream mute state changedFRAME_UNDERRUN (4): Buffer underrun occurred
Returns
Promise<AudioStatus>
A promise that resolves to:
STATUS_NO_ERROR (0): Callback registered successfullySTATUS_NO_INIT (-3): Stream not initializedSTATUS_BAD_VALUE (-2): Invalid callbackSTATUS_ALREADY_EXISTS (-4): Callback already registered
setVolumeAsync()
setVolumeAsync(
gain):Promise<number>
Sets the stream's volume level. This is independent of system volume.
Parameters
gain
number
Volume level (0-100)
Returns
Promise<number>
A promise that resolves to:
STATUS_NO_ERROR (0): Volume set successfullySTATUS_NO_INIT (-3): Stream not initializedSTATUS_BAD_VALUE (-2): Invalid gain valueSTATUS_DEAD_OBJECT (-5): Server communication error
setVolumeWithFadeAsync()
setVolumeWithFadeAsync(
volume,duration,fadeType):Promise<number>
Sets the stream's volume with fade effect.
Parameters
volume
number
Target volume (0-100)
duration
number
Duration in milliseconds
fadeType
Fade curve type
Returns
Promise<number>
A promise that resolves when fade is initiated
STATUS_NO_ERROR (0): Volume set successfullySTATUS_NO_INIT (-3): Stream not initializedSTATUS_BAD_VALUE (-2): Invalid gain valueSTATUS_DEAD_OBJECT (-5): Server communication error
startAsync()
startAsync():
Promise<AudioStatus>
Starts or resumes playback of the stream.
Returns
Promise<AudioStatus>
A promise that resolves to:
STATUS_NO_ERROR (0): Successfully startedSTATUS_NO_INIT (-3): Stream not initializedSTATUS_INVALID_OPERATION (-8): Stream already playingSTATUS_DEAD_OBJECT (-5): Server communication error
stopAsync()
stopAsync():
Promise<AudioStatus>
Stops playback and clears all buffers. Unlike pauseAsync, this discards any buffered data.
Returns
Promise<AudioStatus>
A promise that resolves to:
STATUS_NO_ERROR (0): Successfully stoppedSTATUS_NO_INIT (-3): Stream not initializedSTATUS_INVALID_OPERATION (-8): Stream already stoppedSTATUS_DEAD_OBJECT (-5): Server communication error
unregisterEventObserverAsync()
unregisterEventObserverAsync():
Promise<AudioStatus>
Unregister the previously registered event callback.
Returns
Promise<AudioStatus>
A promise that resolves to:
STATUS_NO_ERROR (0): Callback unregistered successfullySTATUS_NO_INIT (-3): Stream not initializedSTATUS_BAD_VALUE (-2): No callback was registered
writeAsync()
writeAsync(
buffer):Promise<AudioStatus>
Writes audio data to the playback buffer.
Parameters
buffer
ArrayBuffer
Audio data to write
Returns
Promise<AudioStatus>
A promise that resolves to:
- Positive value: Number of bytes written
STATUS_NO_INIT (-3): Stream not initializedSTATUS_BAD_VALUE (-2): Invalid bufferSTATUS_INVALID_OPERATION (-8): Write operation failedSTATUS_WOULD_BLOCK (-6): Buffer fullSTATUS_DEAD_OBJECT (-5): Server communication error
getMajorVersion()
staticgetMajorVersion():number
Gets the major version number of the AudioPlaybackStream implementation. Can be used to make version checks.
Returns
number
The major version number
getMinorVersion()
staticgetMinorVersion():number
Gets the minor version number of the AudioPlaybackStream implementation. Can be used to make version checks.
Returns
number
The minor version number
getPatchVersion()
staticgetPatchVersion():number
Gets the patch version number of the AudioPlaybackStream implementation. Can be used to make version checks.
Returns
number
The patch version number
Last updated: Oct 02, 2025

