as

Settings
Sign out
Notifications
Alexa
亚马逊应用商店
AWS
文档
Support
Contact Us
My Cases
新手入门
设计和开发
应用发布
参考
支持
跳转到主要内容
Audio Playback Stream allows for control of playback streams such as pausing, flushing, and writing to the playback buffer.

Required privileges

The API requires specific privileges for certain operations:
The API also requires declaration of the system audio services:

Types Used

Refer to Audio Core Types

Constructors

new AudioPlaybackStream()

new AudioPlaybackStream(id): AudioPlaybackStream

Parameters

id
number Internal stream identifier

Returns

AudioPlaybackStream

Properties

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 DB (0) or PERCENTAGE (1)
value
Int32 Amount to reduce volume:
  • For DB: 0-144 dB reduction
  • For PERCENTAGE: 0-100% reduction
value = 0 means the stream will be unducked to original stream volume
rampDurationMs
Int32 Time in milliseconds to go from current volume to target volume

Returns

Promise<Int32> Promise<Int32> A promise that resolves to:

Examples


flushAsync()

flushAsync(): Promise<AudioStatus>
Flushes all buffered data without changing the playback state.

Returns

Promise<AudioStatus> Promise<AudioStatus> A promise that resolves to:

Examples


getAudioAttributesAsync()

getAudioAttributesAsync(): Promise<AudioAttributes>
Retrieves the current audio attributes of the playback stream.

Returns

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

Examples


getAudioConfigAsync()

getAudioConfigAsync(): Promise<AudioConfig>
Retrieves the current audio configuration of the playback stream.

Returns

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

Examples


getAudioEffectSessionIdAsync()

getAudioEffectSessionIdAsync(): Promise<Int32>
Gets the custom audio effect session ID associated with this stream.

Returns

Promise<Int32> Promise<Int32> A promise that resolves to:

getAudioFocusSessionIdAsync()

getAudioFocusSessionIdAsync(): Promise<Int32>
Gets the audio focus session ID associated with this stream.

Returns

Promise<Int32> Promise<Int32> A promise that resolves to:

Examples


getBufferCountAsync()

getBufferCountAsync(): Promise<Int32>
Gets the number of buffers configured for this stream.

Returns

Promise<Int32> Promise<Int32> A promise that resolves to:

getChannelCountAsync()

getChannelCountAsync(): Promise<Int32>
Gets the channel count of the playback stream.

Returns

Promise<Int32> Promise<Int32> A promise that resolves to:

Examples


getDuckingPolicyAsync()

getDuckingPolicyAsync(): Promise<Int32>
Gets the current ducking policy of the stream.

Returns

Promise<Int32> Promise<Int32> A promise that resolves to StreamDuckingPolicy:
  • SYSTEM (0): System handles duckicking automatically
  • EXPLICIT (1): Application must handle ducking
Or rejects with:

Examples


getFramesPerBufferAsync()

getFramesPerBufferAsync(): Promise<Int32>
Gets the number of frames per buffer configured for this stream.

Returns

Promise<Int32> Promise<Int32> A promise that resolves to:

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

Examples


getMajorVersion()

static getMajorVersion(): number
Gets the major version number of the AudioPlaybackStream 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 AudioPlaybackStream 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<Int32> A promise that resolves to:

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

Examples


getPatchVersion()

static getPatchVersion(): number
Gets the patch version number of the AudioPlaybackStream 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<Int32> 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

Examples


getSampleRateAsync()

getSampleRateAsync(): Promise<Int32>
Gets the sample rate of the playback stream.

Returns

Promise<Int32> Promise<Int32> A promise that resolves to:

Examples


getSampleSizeAsync()

getSampleSizeAsync(): Promise<Int32>
Gets the sample size in bits of the playback stream.

Returns

Promise<Int32> Promise<Int32> A promise that resolves to:

Examples


getUnderrunCountAsync()

getUnderrunCountAsync(): Promise<Int32>
Gets the total number of underrun occurrences.

Returns

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

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

Examples


getVolumeAsync()

getVolumeAsync(): Promise<Int32>
Gets the stream’s current volume level.

Returns

Promise<Int32> Promise<Int32> A promise that resolves to:

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

Examples


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

Examples


queryMinimumBufferInfoAsync()

queryMinimumBufferInfoAsync(): Promise<Object>
Get minimum buffer information

Returns

Promise<Object> Promise<Object> 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:

Returns

Promise<AudioStatus> Promise<AudioStatus> A promise that resolves to:

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

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 type

Returns

Promise<Int32> Promise<Int32> A promise that resolves when fade is initiated

startAsync()

startAsync(): Promise<AudioStatus>
Starts or resumes playback of the stream.

Returns

Promise<AudioStatus> Promise<AudioStatus> A promise that resolves to:

Examples


stopAsync()

stopAsync(): Promise<AudioStatus>
Stops playback and clears all buffers. Unlike pauseAsync, this discards any buffered data.

Returns

Promise<AudioStatus> Promise<AudioStatus> A promise that resolves to:

Examples


unregisterEventObserverAsync()

unregisterEventObserverAsync(): Promise<AudioStatus>
Unregister the previously registered event callback.

Returns

Promise<AudioStatus> Promise<AudioStatus> A promise that resolves to:

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

Examples

最后修改于 2026年8月25日