Amazon Developer

as

Settings
Sign out
Notifications
Alexa
Amazon Appstore
Ring
AWS
Documentation
Support
Contact Us
My Cases
Get Started
Design and Develop
Publish
Reference
Support
Skip to main content
Audio Playback Stream Builder allows for the configuration, creation, and destruction of Audio Playback Streams.

Required services

The API requires declaration of the system audio services:

Types Used

Refer to * * * * * * * * *

Constructors

new AudioPlaybackStreamBuilder()

new AudioPlaybackStreamBuilder(): AudioPlaybackStreamBuilder

Returns

AudioPlaybackStreamBuilder

Properties

args

args: Object = {}

Methods

buildAsync()

buildAsync(): Promise<AudioPlaybackStream> Creates a new AudioPlaybackStream using the current builder configuration. Must call and before building.

Returns

Promise<AudioPlaybackStream> Promise A promise that resolves to:
  • New instance if successful
Or rejects with:
  • STATUS_BAD_VALUE (-2): Missing required configuration
  • STATUS_NO_INIT (-3): Audio system not initialized
  • STATUS_NO_MEMORY (-1): Failed to allocate resources
  • STATUS_DEAD_OBJECT (-5): Server communication error
  • STATUS_INVALID_OPERATION (-8): Invalid configuration combination

Examples


destroyAsync()

static destroyAsync(playbackStream: AudioPlaybackStream): Promise<AudioStatus> Destroys an existing . 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
AudioPlaybackStream The stream to destroy

Returns

Promise<AudioStatus> Promise A promise that resolves to:
  • STATUS_NO_ERROR (0): Stream destroyed successfully
  • STATUS_BAD_VALUE (-2): Invalid stream object
  • STATUS_NO_INIT (-3): Audio system not initialized
  • STATUS_INVALID_OPERATION (-8): Stream already destroyed

Examples


reset()

reset(): void Resets all builder configuration to default values. Use this to reuse the builder for creating a different stream configuration.

Examples


setAudioAttributes()

setAudioAttributes(attributes: AudioAttributes): void Sets the audio attributes for the stream to be built. This must be called before . These attributes affect how the stream interacts with the audio focus system.

Parameters

attributes
AudioAttributes Audio attributes object containing:
  • contentType: Type of content from enum
  • usage: Usage scenario from enum
  • flags: Behavior flags from enum

Examples


setAudioConfig()

setAudioConfig(config: AudioConfig): void Sets the audio configuration for the stream to be built. This must be called before .

Parameters

config
AudioConfig Audio configuration object containing:
  • sampleRate: Sample rate in Hz from enum
  • channelMask: Channel configuration from enum
  • format: Sample format from enum

Examples


setAudioEffectSessionId()

setAudioEffectSessionId(effectSessionId: Int32): void Sets custom audio effect session ID for the stream. This allows applying custom audio effects to this stream.

Parameters

effectSessionId
Int32 Effect session ID obtained from:

setAudioFocusSessionId()

setAudioFocusSessionId(focusSessionId: Int32): void Sets the audio focus session ID for the stream. This associates the stream with a specific focus session for focus management.

Parameters

focusSessionId
Int32 Focus session ID obtained from:
  • An existing

Examples

Note: The above example assumes the session is an AudioFocusSession object.

setBufferCount()

setBufferCount(bufferCount: Int32): void Sets the number of buffers to use for the stream. More buffers increase latency but provide better protection against underruns.

Parameters

bufferCount
Int32 Number of buffers. Must be greater than 0. Typical values: 2, 3, 4

setDuckingPolicy()

setDuckingPolicy(duckPolicy: StreamDuckingPolicy): void Sets the ducking policy for the stream. This determines how volume reduction is handled when audio focus is ducked. If ducking policy equals to StreamDuckingPolicy::EXPLICIT, the app needs to call duckVolume API to duck the stream volume, otherwise the volume won’t be changed; If set to StreamDuckingPolicy::SYSTEM (by default), the stream volume ducking is handled by the system.

Parameters

duckPolicy
StreamDuckingPolicy The ducking policy:
  • SYSTEM (0): System handles volume reduction automatically
  • EXPLICIT (1): Application must handle volume reduction using calls

Examples


setFramesPerBuffer()

setFramesPerBuffer(framesPerBuffer: Int32): void Sets the number of frames per buffer for the stream. This is used to determine the buffer size per slot in the shared memory buffer queue. Larger values increase latency but improve power efficiency. Smaller values decrease latency but may cause underruns.

Parameters

framesPerBuffer
Int32 Number of frames per buffer. Must be greater than 0. Typical values: 256, 512, 1024, 2048

Examples


setUnderrunThreshold()

setUnderrunThreshold(framesThreshold: Int32): void Sets the threshold for reporting buffer underruns. An underrun occurs when the playback buffer becomes empty.

Parameters

framesThreshold
Int32 Number of frames threshold. When available frames drops below this value, an underrun event will be triggered. Must be greater than 0.

Examples


Last modified on July 22, 2026