AudioPlaybackStreamTurboModule
Extends
KeplerTurboModule
Properties
buildAudioPlaybackStreamAsync()
buildAudioPlaybackStreamAsync: (
args
) =>Promise
<number
>
Creates a new audio playback stream with the specified configuration.
Parameters
args
Object
Configuration object containing:
audio_config
: AudioConfig object with format settingsaudio_attributes
: AudioAttributes object with usage settingsframesPerBuffer
: Number of frames per bufferaudioFocusSessionId
: Optional focus session IDaudioEffectSessionId
: Optional effect session IDbufferCount
: Number of buffers to allocateframesThreshold
: Threshold for underrun detectionduckPolicy
: Stream ducking policy
Returns
Promise
<number
>
A promise that resolves to:
- Positive number: New stream ID on success
STATUS_NO_MEMORY (-1)
: Memory allocation failedSTATUS_BAD_VALUE (-2)
: Invalid configurationSTATUS_PERMISSION_DENIED (-9)
: Insufficient privileges
destroyAudioPlaybackStreamAsync()
destroyAudioPlaybackStreamAsync: (
streamId
) =>Promise
<number
>
Destroys an existing audio playback stream.
Parameters
streamId
number
ID of the stream to destroy
Returns
Promise
<number
>
A promise that resolves to:
STATUS_NO_ERROR (0)
: SuccessSTATUS_BAD_VALUE (-2)
: Invalid stream IDSTATUS_NO_INIT (-3)
: Stream not initializedSTATUS_INVALID_OPERATION (-8)
: Stream in invalid state
duckVolumeAsync()
duckVolumeAsync: (
streamId
,mode
,value
,rampDurationMs
) =>Promise
<number
>
Ducks (reduces) or unducks the stream volume using specified parameters. Only works if ducking policy is set to EXPLICIT.
Parameters
streamId
number
ID of the stream
mode
number
Ducking mode:
DuckingMode.DB (0)
: Value represents dB reduction
DuckingMode.PERCENTAGE (1)
: Value represents percentage reduction
value
number
Amount to reduce volume:
For DB mode: 0-144 dB
For PERCENTAGE mode: 0-100%
0
in either mode unducks to original volume
rampDurationMs
number
Duration in milliseconds to transition to target volume
Returns
Promise
<number
>
A promise that resolves to:
STATUS_NO_ERROR (0)
: SuccessSTATUS_BAD_VALUE (-2)
: Invalid parametersSTATUS_NO_INIT (-3)
: Stream not initializedSTATUS_INVALID_OPERATION (-8)
: Policy not set to EXPLICITSTATUS_DEAD_OBJECT (-5)
: Server connection lost
flushAsync()
flushAsync: (
streamId
) =>Promise
<number
>
Flushes any pending audio data from the stream.
Parameters
streamId
number
ID of the stream
Returns
Promise
<number
>
A promise that resolves to:
STATUS_NO_ERROR (0)
: SuccessSTATUS_BAD_VALUE (-2)
: Invalid stream IDSTATUS_NO_INIT (-3)
: Stream not initializedSTATUS_INVALID_OPERATION (-8)
: Invalid state for flushSTATUS_DEAD_OBJECT (-5)
: Server connection lost
getAudioAttributesAsync()
getAudioAttributesAsync: (
streamId
) =>Promise
<Object
>
Gets the audio attributes of the stream.
Parameters
streamId
number
ID of the stream
Returns
Promise
<Object
>
A promise that resolves to an object containing:
content_type
: Type of content (SPEECH, MUSIC, etc)usage
: Usage type (MEDIA, ALARM, etc)flags
: Special behavior flags
Rejects with:
STATUS_BAD_VALUE (-2)
: Invalid stream IDSTATUS_NO_INIT (-3)
: Stream not initializedSTATUS_DEAD_OBJECT (-5)
: Server connection lost
getAudioConfigAsync()
getAudioConfigAsync: (
streamId
) =>Promise
<Object
>
Gets the audio configuration of the stream.
Parameters
streamId
number
ID of the stream
Returns
Promise
<Object
>
A promise that resolves to an object containing:
sample_rate
: Sample rate in Hzchannel_mask
: Channel configurationformat
: Audio format type
Rejects with:
STATUS_BAD_VALUE (-2)
: Invalid stream IDSTATUS_NO_INIT (-3)
: Stream not initializedSTATUS_DEAD_OBJECT (-5)
: Server connection lost
getAudioEffectSessionIdAsync()
getAudioEffectSessionIdAsync: (
streamId
) =>Promise
<number
>
Gets the audio effect session ID associated with this stream.
Parameters
streamId
number
ID of the stream
Returns
Promise
<number
>
A promise that resolves to:
- Positive number: Audio effect session ID
STATUS_BAD_VALUE (-2)
: Invalid stream IDSTATUS_NO_INIT (-3)
: Stream not initializedSTATUS_DEAD_OBJECT (-5)
: Server connection lost
getAudioFocusSessionIdAsync()
getAudioFocusSessionIdAsync: (
streamId
) =>Promise
<number
>
Gets the audio focus session ID associated with this stream.
Parameters
streamId
number
ID of the stream
Returns
Promise
<number
>
A promise that resolves to:
- Positive number: Audio focus session ID
STATUS_BAD_VALUE (-2)
: Invalid stream IDSTATUS_NO_INIT (-3)
: Stream not initializedSTATUS_DEAD_OBJECT (-5)
: Server connection lost
getBufferCountAsync()
getBufferCountAsync: (
streamId
) =>Promise
<number
>
Gets the number of buffers allocated for this stream.
Parameters
streamId
number
ID of the stream
Returns
Promise
<number
>
A promise that resolves to:
- Positive number: Number of buffers
STATUS_BAD_VALUE (-2)
: Invalid stream IDSTATUS_NO_INIT (-3)
: Stream not initializedSTATUS_DEAD_OBJECT (-5)
: Server connection lost
getChannelCountAsync()
getChannelCountAsync: (
streamId
) =>Promise
<number
>
Gets the channel count of the stretream.
Parameters
streamId
number
ID of the stream
Returns
Promise
<number
>
A promise that resolves to:
- Positive number: Number of channels
STATUS_BAD_VALUE (-2)
: Invalid stream IDSTATUS_NO_INIT (-3)
: Stream not initializedSTATUS_DEAD_OBJECT (-5)
: Server er connection lost
getDuckingPolicyAsync()
getDuckingPolicyAsync: (
streamId
) =>Promise
<number
>
Gets the current ducking policy of the stream.
Parameters
streamId
number
ID of the stream
Returns
Promise
<number
>
A promise that resolves to:
StreamDuckingPolicy.SYSTEM (0)
: System handles ducking automaticallyStreamDuckingPolicy.EXPLICIT (1)
: Application must handle duckingSTATUS_BAD_VALUE (-2)
: Invalid stream IDSTATUS_NO_INIT (-3)
: Stream not initializedSTATUS_DEAD_OBJECT (-5)
: Server connection lost
getFramesPerBufferAsync()
getFramesPerBufferAsync: (
streamId
) =>Promise
<number
>
Gets the number of frames per buffer.
Parameters
streamId
number
ID of the stream
Returns
Promise
<number
>
A promise that resolves to:
- Positive number: Frames per buffer
STATUS_BAD_VALUE (-2)
: Invalid stream IDSTATUS_NO_INIT (-3)
: Stream not initializedSTATUS_DEAD_OBJECT (-5)
: Server connection lost
getLatencyInMsAsync()
getLatencyInMsAsync: (
streamId
) =>Promise
<number
>
Gets the latency of the audio stream in milliseconds.
Parameters
streamId
number
ID of the stream
Returns
Promise
<number
>
A promise that resolves to:
- Positive number: Latency in milliseconds
STATUS_BAD_VALUE (-2)
: Invalid stream IDSTATUS_NO_INIT (-3)
: Stream not initializedSTATUS_DEAD_OBJECT (-5)
: Server connection lost
getMajorVersion()
readonly
getMajorVersion: () =>number
Gets the major version number of the AudioPlaybackStreamTurboModule. Can be used to make version checks.
Returns
number
The major version number
Overrides
KeplerTurboModule.getMajorVersion
getMinorVersion()
readonly
getMinorVersion: () =>number
Gets the minor version number of the AudioPlaybackStreamTurboModule. Can be used to make version checks.
Returns
number
The minor version number
Overrides
KeplerTurboModule.getMinorVersion
getNumBytesInPipelineAsync()
getNumBytesInPipelineAsync: (
streamId
) =>Promise
<number
>
Gets the number of bytes currently in the audio pipeline.
Parameters
streamId
number
ID of the stream
Returns
Promise
<number
>
A promise that resolves to:
- Positive number: Number of bytes in pipeline
STATUS_BAD_VALUE (-2)
: Invalid stream IDSTATUS_NO_INIT (-3)
: Stream not initializedSTATUS_DEAD_OBJECT (-5)
: Server connection lost
getNumBytesOfNativeBufferAsync()
getNumBytesOfNativeBufferAsync: (
streamId
) =>Promise
<number
>
Gets the size of the native buffer in bytes.
Parameters
streamId
number
ID of the stream
Returns
Promise
<number
>
A promise that resolves to:
- Positive number: Buffer size in bytes
STATUS_BAD_VALUE (-2)
: Invalid stream IDSTATUS_NO_INIT (-3)
: Stream not initializedSTATUS_DEAD_OBJECT (-5)
: Server connection lost
getPatchVersion()
readonly
getPatchVersion: () =>number
Gets the patch version number of the AudioPlaybackStreamTurboModule. Can be used to make version checks.
Returns
number
The patch version number
Overrides
KeplerTurboModule.getPatchVersion
getPresentedFrameCountAsync()
getPresentedFrameCountAsync: (
streamId
) =>Promise
<number
>
Gets the total number of audio frames that have been successfully presented to the audio pipeline since stream creation.
Parameters
streamId
number
ID of the stream
Returns
Promise
<number
>
A promise that resolves to:
- Positive number: Number of presented frames
STATUS_BAD_VALUE (-2)
: Invalid stream IDSTATUS_NO_INIT (-3)
: Stream not initializedSTATUS_DEAD_OBJECT (-5)
: Server connection lost
getSampleRateAsync()
getSampleRateAsync: (
streamId
) =>Promise
<number
>
Gets the sample rate of the stream.
Parameters
streamId
number
ID of the stream
Returns
Promise
<number
>
A promise that resolves to:
- Positive number: Sample rate in Hz
STATUS_BAD_VALUE (-2)
: Invalid stream IDSTATUS_NO_INIT (-3)
: Stream not initializedSTATUS_DEAD_OBJECT (-5)
: Server connection lost
getSampleSizeAsync()
getSampleSizeAsync: (
streamId
) =>Promise
<number
>
Gets the sample size in bits.
Parameters
streamId
number
ID of the stream
Returns
Promise
<number
>
A promise that resolves to:
- Positive number: Sample size in bits
STATUS_BAD_VALUE (-2)
: Invalid stream ID IDSTATUS_NO_INIT (-3)
: Stream not initializedSTATUS_DEAD_OBJECT (-5)
: Server connection lost
getUnderrunCountAsync()
getUnderrunCountAsync: (
streamId
) =>Promise
<number
>
Gets the total number of buffer underruns that have occurred during stream lifetime.
Parameters
streamId
number
ID of the stream
Returns
Promise
<number
>
A promise that resolves to:
- Positive number: Number of underrun occurrences
STATUS_BAD_VALUE (-2)
: Invalid stream IDSTATUS_NO_INIT (-3)
: Stream not initializedSTATUS_DEAD_OBJECT (-5)
: Server connection lost
getUnderrunSizeAsync()
getUnderrunSizeAsync: (
streamId
) =>Promise
<number
>
Gets the difference between current buffer size and underrun threshold in frames. Only returns non-zero value if buffer is in underrun state and a threshold was set.
Parameters
streamId
number
ID of the stream
Returns
Promise
<number
>
A promise that resolves to:
- Positive number: Difference in frames between buffer size and threshold
- 0: No underrun or no threshold set
STATUS_BAD_VALUE (-2)
: Invalid stream IDSTATUS_NO_INIT (-3)
: Stream not initializedSTATUS_DEAD_OBJECT (-5)
: Server connection lost
getVolumeAsync()
getVolumeAsync: (
streamId
) =>Promise
<number
>
Gets the stream's current volume as a percentage of system volume.
Parameters
streamId
number
ID of the stream
Returns
Promise
<number
>
A promise that resolves to:
- 0-100: Current volume percentage
STATUS_BAD_VALUE (-2)
: Invalid stream IDSTATUS_NO_INIT (-3)
: Stream not initializedSTATUS_DEAD_OBJECT (-5)
: Server connection lost
initCheckAsync()
initCheckAsync: (
streamId
) =>Promise
<number
>
Checks if the stream is properly initialized.
Parameters
streamId
number
ID of the stream to check
Returns
Promise
<number
>
A promise that resolves to:
STATUS_NO_ERROR (0)
: Stream initializedSTATUS_NO_INIT (-3)
: Stream not initializedSTATUS_BAD_VALUE (-2)
: Invalid stream IDSTATUS_DEAD_OBJECT (-5)
: Server connection lost
pauseAsync()
pauseAsync: (
streamId
) =>Promise
<number
>
Pauses the audio stream.
Parameters
streamId
number
ID of the stream
Returns
Promise
<number
>
A promise that resolves to:
STATUS_NO_ERROR (0)
: SuccessSTATUS_BAD_VALUE (-2)
: Invalid stream IDSTATUS_NO_INIT (-3)
: Stream not initializedSTATUS_INVALID_OPERATION (-8)
: Invalid state for pauseSTATUS_DEAD_OBJECT (-5)
: Server connection lost
queryMinimumBufferInfoAsync()
queryMinimumBufferInfoAsync: (
config
,attr
) =>Promise
<Object
>
Queries minimum buffer information for given audio configuration.
Parameters
config
Object
Audio configuration
attr
Object
Audio attributes
Returns
Promise
<Object
>
A promise that resolves to an object containing:
minFramesPerBuffer
: Minimum frames per bufferminBufferCount
: Minimum number of buffers
Rejects with:
STATUS_BAD_VALUE (-2)
: Invalid configurationSTATUS_NO_INIT (-3)
: System not initializedSTATUS_DEAD_OBJECT (-5)
: Server connection lost
registerEventObserverAsync()
registerEventObserverAsync: (
streamId
,callback
) =>Promise
<number
>
Registers a callback function for stream events.
Parameters
streamId
number
ID of the stream
callback
(value
) => void
Callback function to handle events:
DIED (0)
: Stream became unavailableRECOVERED (1)
: Stream recoveredSTOPPED (2)
: Stream stoppedMUTE_STATE_UPDATE (3)
: Mute state changedFRAME_UNDERRUN (4)
: Buffer underrun occurred
Returns
Promise
<number
>
A promise that resolves to:
STATUS_NO_ERROR (0)
: SuccessSTATUS_BAD_VALUE (-2)
: Invalid stream ID or callbackSTATUS_NO_INIT (-3)
: Stream not initializedSTATUS_ALREADY_EXISTS (-4)
: Callback already registeredSTATUS_DEAD_OBJECT (-5)
: Server connection lost
setVolumeAsync()
setVolumeAsync: (
streamId
,gain
) =>Promise
<number
>
Sets the stream's volume as a percentage of system volume.
Parameters
streamId
number
ID of the stream
gain
number
Volume level as percentage (0-100)
Returns
Promise
<number
>
A promise that resolves to:
STATUS_NO_ERROR (0)
: SuccessSTATUS_BAD_VALUE (-2)
: Invalid stream ID or gain valueSTATUS_NO_INIT (-3)
: Stream not initializedSTATUS_DEAD_OBJECT (-5)
: Server connection lost
startAsync()
startAsync: (
streamId
) =>Promise
<number
>
Starts or resumes the audio stream.
Parameters
streamId
number
ID of the stream
Returns
Promise
<number
>
A promise that resolves to:
STATUS_NO_ERROR (0)
: SuccessSTATUS_BAD_VALUE (-2)
: Invalid stream IDSTATUS_NO_INIT (-3)
: Stream not initializedSTATUS_INVALID_OPERATION (-8)
: Invalid state for startSTATUS_DEAD_OBJECT (-5)
: Server connection lost
stopAsync()
stopAsync: (
streamId
) =>Promise
<number
>
Stops the audio stream.
Parameters
streamId
number
ID of the stream
Returns
Promise
<number
>
A promise that resolves to:
STATUS_NO_ERROR (0)
: SuccessSTATUS_BAD_VALUE (-2)
: Invalid stream IDSTATUS_NO_INIT (-3)
: Stream not initializedSTATUS_INVALID_OPERATION (-8)
: Invalid state for stopSTATUS_DEAD_OBJECT (-5)
: Server connection lost
unregisterEventObserverAsync()
unregisterEventObserverAsync: (
streamId
) =>Promise
<number
>
Unregister the event callback for the stream.
Parameters
streamId
number
ID of the stream
Returns
Promise
<number
>
A promise that resolves to:
STATUS_NO_ERROR (0)
: SuccessSTATUS_BAD_VALUE (-2)
: Invalid stream IDSTATUS_NO_INIT (-3)
: Stream not initializedSTATUS_INVALID_OPERATION (-8)
: No callback registeredSTATUS_DEAD_OBJECT (-5)
: Server connection lost
writeAsync()
writeAsync: (
streamId
,buffer
) =>Promise
<number
>
Writes audio data to the stream.
Parameters
streamId
number
ID of the stream
buffer
ArrayBuffer
Audio data to write
Returns
Promise
<number
>
A promise that resolves to:
- Positive number: Number of bytes written
STATUS_BAD_VALUE (-2)
: Invalid stream ID or bufferSTATUS_NO_INIT (-3)
: Stream not initializedSTATUS_WOULD_BLOCK (-6)
: Buffer fullSTATUS_DEAD_OBJECT (-5)
: Server connection lost
Methods
getConstants()?
optional
getConstants():object
Returns
object
Inherited from
KeplerTurboModule.getConstants
Last updated: Sep 30, 2025