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

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 setAudioConfig and setAudioAttributes before building.

Returns

Promise<AudioPlaybackStream> A promise that resolves to: 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

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
AudioAttributes 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
AudioConfig Audio configuration object containing:
  • sampleRate: Sample rate in Hz from types/AudioCoreClientTypes.AudioSampleRate enum
  • channelMask: Channel configuration from types/AudioCoreClientTypes.AudioChannelMask enum
  • format: 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
StreamDuckingPolicy The ducking policy:

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
AudioPlaybackStream The stream to destroy

Returns

Promise<AudioStatus> 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

Last modified on October 2, 2025