as

Settings
Sign out
Notifications
Alexa
亚马逊应用商店
AWS
文档
Support
Contact Us
My Cases
新手入门
设计和开发
应用发布
参考
支持
跳转到主要内容
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 Audio Core Types

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

Examples


destroyAsync()

static destroyAsync(playbackStream: AudioPlaybackStream): 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> 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

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 buildAsync. These attributes affect how the stream interacts with the audio focus system.

Parameters

attributes
AudioAttributes Audio attributes object containing:

Examples


setAudioConfig()

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

Parameters

config
AudioConfig Audio configuration object containing:

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: AudioManager.allocateCustomAudioEffectSessionAsync

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:

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:

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

最后修改于 2026年8月25日