as

Settings
Sign out
Notifications
Alexa
Amazon Appstore
AWS
Documentation
Support
Contact Us
My Cases
Get Started
Design and Develop
Publish
Reference
Support

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

AudioPlaybackStream

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 successfully
  • STATUS_NO_INIT (-3): Stream not initialized
  • STATUS_BAD_VALUE (-2): Invalid parameters
  • STATUS_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 flushed
  • STATUS_NO_INIT (-3): Stream not initialized
  • STATUS_INVALID_OPERATION (-8): Cannot flush while playing
  • STATUS_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 played
  • usage: Usage category of the stream
  • flags: Current behavior flags Or rejects with:
  • STATUS_NO_INIT (-3): Stream not initialized
  • STATUS_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 Hz
  • channelMask: Current channel configuration
  • format: Current sample format Or rejects with:
  • STATUS_NO_INIT (-3): Stream not initialized
  • STATUS_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 initialized
  • STATUS_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 initialized
  • STATUS_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 initialized
  • STATUS_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 initialized
  • STATUS_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 automatically
  • EXPLICIT (1): Application must handle ducking

Or rejects with:

  • STATUS_NO_INIT (-3): Stream not initialized
  • STATUS_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 initialized
  • STATUS_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 initialized
  • STATUS_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 initialized
  • STATUS_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 initialized
  • STATUS_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 initialized
  • STATUS_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 initialized
  • STATUS_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 initialized
  • STATUS_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 initialized
  • STATUS_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 initialized
  • STATUS_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 initialized
  • STATUS_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 initialized
  • STATUS_NO_INIT (-3): Stream not initialized
  • STATUS_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 paused
  • STATUS_NO_INIT (-3): Stream not initialized
  • STATUS_INVALID_OPERATION (-8): Stream already paused
  • STATUS_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 failed
  • RECOVERED (1): Stream has recovered from failure
  • STOPPED (2): Playback has stopped
  • MUTE_STATE_UPDATE (3): Stream mute state changed
  • FRAME_UNDERRUN (4): Buffer underrun occurred

Returns

Promise<AudioStatus>

A promise that resolves to:

  • STATUS_NO_ERROR (0): Callback registered successfully
  • STATUS_NO_INIT (-3): Stream not initialized
  • STATUS_BAD_VALUE (-2): Invalid callback
  • STATUS_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 successfully
  • STATUS_NO_INIT (-3): Stream not initialized
  • STATUS_BAD_VALUE (-2): Invalid gain value
  • STATUS_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 started
  • STATUS_NO_INIT (-3): Stream not initialized
  • STATUS_INVALID_OPERATION (-8): Stream already playing
  • STATUS_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 stopped
  • STATUS_NO_INIT (-3): Stream not initialized
  • STATUS_INVALID_OPERATION (-8): Stream already stopped
  • STATUS_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 successfully
  • STATUS_NO_INIT (-3): Stream not initialized
  • STATUS_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 initialized
  • STATUS_BAD_VALUE (-2): Invalid buffer
  • STATUS_INVALID_OPERATION (-8): Write operation failed
  • STATUS_WOULD_BLOCK (-6): Buffer full
  • STATUS_DEAD_OBJECT (-5): Server communication error

getMajorVersion()

static getMajorVersion(): number

Gets the major version number of the AudioPlaybackStream implementation. Can be used to make version checks.

Returns

number

The major version number


getMinorVersion()

static getMinorVersion(): number

Gets the minor version number of the AudioPlaybackStream implementation. Can be used to make version checks.

Returns

number

The minor version number


getPatchVersion()

static getPatchVersion(): 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: Sep 30, 2025