Required privileges
The API requires specific privileges for certain operations:Types Used
Refer to * * * * * * *Constructors
new AudioPlaybackStream()
new AudioPlaybackStream(id): AudioPlaybackStream
Parameters
id
number
Internal stream identifier
Returns
AudioPlaybackStreamProperties
streamId
streamId:number
Methods
duckVolumeAsync()
duckVolumeAsync(mode:Int32, value: Int32, rampDurationMs: Int32): Promise<Int32>
Adjusts the volume of the stream for ducking purposes.
Only effective when using EXPLICIT ducking policy.
Parameters
mode
Int32
(0) or (1)
value
Int32
Amount to reduce volume:
- For
DB: 0-144 dB reduction - For
PERCENTAGE: 0-100% reduction
rampDurationMs
Int32
Time in milliseconds to go from current volume to target volume
Returns
Promise<Int32>
Promise A promise that resolves to:
- (0): Volume ducked successfully
- (-3): Stream not initialized
- (-2): Invalid parameters
- (-8): Wrong ducking policy
Examples
flushAsync()
flushAsync():Promise<AudioStatus>
Flushes all buffered data without changing the playback state.
Returns
Promise<AudioStatus>
Promise A promise that resolves to:
- (0): Successfully flushed
- (-3): Stream not initialized
- (-8): Cannot flush while playing
- (-5): Server communication error
Examples
getAudioAttributesAsync()
getAudioAttributesAsync():Promise<AudioAttributes>
Retrieves the current audio attributes of the playback stream.
Returns
Promise<AudioAttributes>
Promise A promise that resolves to an object containing:
contentType: Type of content being playedusage: Usage category of the streamflags: Current behavior flags Or rejects with:- (-3): Stream not initialized
- (-5): Server communication error
Examples
getAudioConfigAsync()
getAudioConfigAsync():Promise<AudioConfig>
Retrieves the current audio configuration of the playback stream.
Returns
Promise<AudioConfig>
Promise A promise that resolves to an object containing:
sampleRate: Current sample rate in HzchannelMask: Current channel configurationformat: Current sample format Or rejects with:- (-3): Stream not initialized
- (-5): Server communication error
Examples
getAudioEffectSessionIdAsync()
getAudioEffectSessionIdAsync():Promise<Int32>
Gets the custom audio effect session ID associated with this stream.
Returns
Promise<Int32>
Promise A promise that resolves to:
- Positive value: The effect session ID
- (-3): Stream not initialized
- (-2): No effect session assigned
getAudioFocusSessionIdAsync()
getAudioFocusSessionIdAsync():Promise<Int32>
Gets the audio focus session ID associated with this stream.
Returns
Promise<Int32>
Promise A promise that resolves to:
- Positive value: The focus session ID
- (-3): Stream not initialized
- (-2): No focus session assigned
Examples
getBufferCountAsync()
getBufferCountAsync():Promise<Int32>
Gets the number of buffers configured for this stream.
Returns
Promise<Int32>
Promise A promise that resolves to:
- Positive value: Number of buffers
- (-3): Stream not initialized
- (-5): Server communication error
getChannelCountAsync()
getChannelCountAsync():Promise<Int32>
Gets the channel count of the playback stream.
Returns
Promise<Int32>
Promise A promise that resolves to:
- Positive value: Number of channels
- (-3): Stream not initialized
- (-5): Server communication error
Examples
getDuckingPolicyAsync()
getDuckingPolicyAsync():Promise<Int32>
Gets the current ducking policy of the stream.
Returns
Promise<Int32>
Promise A promise that resolves to :
- (0): System handles duckicking automatically
- (1): Application must handle ducking
- (-3): Stream not initialized
- (-5): Server communication error
Examples
getFramesPerBufferAsync()
getFramesPerBufferAsync():Promise<Int32>
Gets the number of frames per buffer configured for this stream.
Returns
Promise<Int32>
Promise A promise that resolves to:
- Positive value: Frames per buffer
- (-3): Stream not initialized
- (-5): Server communication error
Examples
getLatencyInMsAsync()
getLatencyInMsAsync():Promise<Int32>
Gets the current latency of the playback stream in milliseconds.
This includes both buffer and hardware latency.
Returns
Promise<Int32>
Promise A promise that resolves to:
- Positive value: Latency in milliseconds
- (-3): Stream not initialized
- (-5): Server communication error
Examples
getMajorVersion()
static getMajorVersion(): number
Gets the major version number of the implementation.
Can be used to make version checks.
Returns
number
number The major version number
getMinorVersion()
static getMinorVersion(): number
Gets the minor version number of the implementation.
Can be used to make version checks.
Returns
number
number The minor version number
getNumBytesInPipelineAsync()
getNumBytesInPipelineAsync():Promise<Int32>
Gets the number of bytes currently in the playback pipeline waiting to be played.
Returns
Promise<Int32>
Promise A promise that resolves to:
- Positive value: Number of bytes in pipeline
- (-3): Stream not initialized
- (-5): Server communication error
Examples
getNumBytesOfNativeBufferAsync()
getNumBytesOfNativeBufferAsync():Promise<Int32>
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<Int32>
Promise A promise that resolves to:
- Positive value: Buffer size in bytes
- (-3): Stream not initialized
- (-5): Server communication error
Examples
getPatchVersion()
static getPatchVersion(): number
Gets the patch version number of the implementation.
Can be used to make version checks.
Returns
number
number The patch version number
getPresentedFrameCountAsync()
getPresentedFrameCountAsync():Promise<Int32>
Gets the total number of frames that have been played.
Returns
Promise<Int32>
Promise A promise that resolves to:
- Positive value: Number of frames played to audio pipeline on success.
- (-3): Stream not initialized
- (-5): Server communication error
Examples
getSampleRateAsync()
getSampleRateAsync():Promise<Int32>
Gets the sample rate of the playback stream.
Returns
Promise<Int32>
Promise A promise that resolves to:
- Positive value: Sample rate in Hz
- (-3): Stream not initialized
- (-5): Server communication error
Examples
getSampleSizeAsync()
getSampleSizeAsync():Promise<Int32>
Gets the sample size in bits of the playback stream.
Returns
Promise<Int32>
Promise A promise that resolves to:
- Positive value: Sample size in bits (e.g., 16, 24, 32)
- (-3): Stream not initialized
- (-5): Server communication error
Examples
getUnderrunCountAsync()
getUnderrunCountAsync():Promise<Int32>
Gets the total number of underrun occurrences.
Returns
Promise<Int32>
Promise A promise that resolves to:
- Positive value: Number of underrun occurrences during stream lifetime.
- (-3): Stream not initialized
- (-5): Server communication error
Examples
getUnderrunSizeAsync()
getUnderrunSizeAsync():Promise<Int32>
Gets the underrun size in frames.
An underrun occurs when the playback buffer becomes empty.
If a client has set a buffer underrun threshold and playback buffer is in underrun state,
this API will return the difference between the buffer size and the threshold value.
Otherwise, this API will return 0.
Returns
Promise<Int32>
Promise A promise that resolves to:
- Positive value: Difference in frames between buffer size and underrun threshold. Frame value is rounded up.
-
0: No underrun - (-3): Stream not initialized
- (-5): Server communication error
Examples
getVolumeAsync()
getVolumeAsync():Promise<Int32>
Gets the stream’s current volume level.
Returns
Promise<Int32>
Promise A promise that resolves to:
- 0-100: Current volume level
- (-3): Stream not initialized
- (-5): Server communication error
Examples
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>
Promise A promise that resolves to:
- (0): Stream is properly initialized
- (-3): Stream not initialized
- (-5): Server communication error
Examples
pauseAsync()
pauseAsync():Promise<AudioStatus>
Pauses playback of the stream.
Data in the buffer is retained and playback can be resumed with .
Returns
Promise<AudioStatus>
Promise A promise that resolves to:
- (0): Successfully paused
- (-3): Stream not initialized
- (-8): Stream already paused
- (-5): Server communication error
Examples
queryMinimumBufferInfoAsync()
queryMinimumBufferInfoAsync():Promise<Object>
Get minimum buffer information
Returns
Promise<Object>
Promise object with fields minFramesPerBuffer and minBufferCount
registerEventObserverAsync()
registerEventObserverAsync(callback:(value: any) => void): Promise<AudioStatus>
Registers a callback to receive playback stream events.
Only one callback can be registered at a time.
Parameters
callback
(value: any) => void
Function to receive events. Events include:
- (0): Stream has failed
- (1): Stream has recovered from failure
- (2): Playback has stopped
- (3): Stream mute state changed
- (4): Buffer underrun occurred
Returns
Promise<AudioStatus>
Promise A promise that resolves to:
- (0): Callback registered successfully
- (-3): Stream not initialized
- (-2): Invalid callback
- (-4): Callback already registered
Examples
setVolumeAsync()
setVolumeAsync(gain:Int32): Promise<Int32>
Set individual stream volume by absolute gain in percentage.set gain of individual stream;
It will be multiplied on stream volume. This is independent of system volume.
Parameters
gain
Int32
Volume level (0-100)
Returns
Promise<Int32>
Promise A promise that resolves to:
- (0): Volume set successfully
- (-3): Stream not initialized
- (-2): Invalid gain value
- (-5): Server communication error
Examples
setVolumeWithFadeAsync()
setVolumeWithFadeAsync(volume:Int32, duration: Int32, fadeType: AudioFadeType): Promise<Int32>
Sets the stream’s volume with fade effect.
Parameters
volume
Int32
Target volume (0-100)
duration
Int32
Duration in milliseconds
fadeType
AudioFadeType Fade curve typeReturns
Promise<Int32>
Promise A promise that resolves when fade is initiated
- (0): Volume set successfully
- (-3): Stream not initialized
- (-2): Invalid gain value
- (-5): Server communication error
startAsync()
startAsync():Promise<AudioStatus>
Starts or resumes playback of the stream.
Returns
Promise<AudioStatus>
Promise A promise that resolves to:
- (0): Successfully started
- (-3): Stream not initialized
- (-8): Stream already playing
- (-5): Server communication error
Examples
stopAsync()
stopAsync():Promise<AudioStatus>
Stops playback and clears all buffers.
Unlike , this discards any buffered data.
Returns
Promise<AudioStatus>
Promise A promise that resolves to:
- (0): Successfully stopped
- (-3): Stream not initialized
- (-8): Stream already stopped
- (-5): Server communication error
Examples
unregisterEventObserverAsync()
unregisterEventObserverAsync():Promise<AudioStatus>
Unregister the previously registered event callback.
Returns
Promise<AudioStatus>
Promise A promise that resolves to:
- (0): Callback unregistered successfully
- (-3): Stream not initialized
- (-2): No callback was registered
Examples
writeAsync()
writeAsync(buffer:ArrayBuffer): Promise<AudioStatus>
Writes audio data to the playback buffer.
Parameters
buffer
ArrayBuffer
Audio data to write
Returns
Promise<AudioStatus>
Promise A promise that resolves to:
- Positive value: Number of bytes written
- (-3): Stream not initialized
- (-2): Invalid buffer
- (-8): Write operation failed
- (-6): Buffer full
- (-5): Server communication error

