AudioOutput
interface AudioOutput
AudioTrackAudioOutput |
A default implementation of |
ForwardingAudioOutput |
A forwarding base class that delegates all calls to the provided |
An interface to wrap an object that can play audio, like an AudioTrack.
Summary
Nested types |
|---|
interface AudioOutput.ListenerListener for |
class AudioOutput.WriteException : ExceptionThrown when a failure occurs writing to the output. |
Public functions |
|
|---|---|
Unit |
addListener(listener: AudioOutput.Listener!)Adds a |
Unit |
attachAuxEffect(effectId: Int)Attaches an auxiliary effect to the output. |
Boolean |
@UnstableApiReturns if the configurations are sufficiently compatible to reuse this audio output. |
Unit |
flush()Flushes the audio data from the output. |
Int |
Returns the audio session ID or |
Long |
Returns the buffer size in frames of the underlying |
PlaybackParameters! |
Returns the playback parameters. |
Long |
Returns the current playout timestamp in microseconds. |
Int |
Returns the sample rate of the underlying |
Boolean |
Returns whether this output is playing back in offload mode. |
Boolean |
Returns whether the audio output is stalled. |
Unit |
pause()Pauses playback. |
Unit |
play()Starts or resumes playing audio. |
Unit |
release()Releases the |
Unit |
removeListener(listener: AudioOutput.Listener!)Removes a |
Unit |
setAuxEffectSendLevel(level: Float)Sets the send level for the auxiliary effect. |
Unit |
setOffloadDelayPadding(delayInFrames: Int, paddingInFrames: Int)Sets the offload delay and padding. |
Unit |
Notifies the output that this is the end of the stream. |
Unit |
setPlaybackParameters(playbackParams: PlaybackParameters!)Sets the playback parameters. |
Unit |
@UnstableApiSets the |
Unit |
setPreferredDevice(preferredDevice: AudioDeviceInfo?)Sets the preferred audio device for routing, or null for no preference. |
Unit |
Sets the volume of the |
Unit |
stop()Signal that the last buffer has been written and playback should stop after playing out all remaining buffers |
Boolean |
write(Writes audio data to the audio output for playback with a presentation timestamp. |
Public functions
addListener
fun addListener(listener: AudioOutput.Listener!): Unit
Adds a Listener for audio output events.
attachAuxEffect
fun attachAuxEffect(effectId: Int): Unit
Attaches an auxiliary effect to the output.
canReuseAudioOutput
@UnstableApi
fun canReuseAudioOutput(
currentConfig: AudioOutputProvider.OutputConfig!,
newFormat: AudioOutputProvider.FormatConfig!,
newConfig: AudioOutputProvider.OutputConfig!
): Boolean
Returns if the configurations are sufficiently compatible to reuse this audio output.
getAudioSessionId
fun getAudioSessionId(): Int
Returns the audio session ID or AUDIO_SESSION_ID_UNSET if unknown.
getBufferSizeInFrames
fun getBufferSizeInFrames(): Long
Returns the buffer size in frames of the underlying AudioOutput.
getPlaybackParameters
fun getPlaybackParameters(): PlaybackParameters!
Returns the playback parameters.
isOffloadedPlayback
fun isOffloadedPlayback(): Boolean
Returns whether this output is playing back in offload mode.
removeListener
fun removeListener(listener: AudioOutput.Listener!): Unit
Removes a Listener for audio output events.
setAuxEffectSendLevel
fun setAuxEffectSendLevel(level: Float): Unit
Sets the send level for the auxiliary effect.
setOffloadDelayPadding
fun setOffloadDelayPadding(delayInFrames: Int, paddingInFrames: Int): Unit
Sets the offload delay and padding.
setOffloadEndOfStream
fun setOffloadEndOfStream(): Unit
Notifies the output that this is the end of the stream.
setPlaybackParameters
fun setPlaybackParameters(playbackParams: PlaybackParameters!): Unit
Sets the playback parameters.
setPlayerId
@UnstableApi
fun setPlayerId(playerId: PlayerId!): Unit
Sets the PlayerId on the audio output.
setPreferredDevice
fun setPreferredDevice(preferredDevice: AudioDeviceInfo?): Unit
Sets the preferred audio device for routing, or null for no preference.
stop
fun stop(): Unit
Signal that the last buffer has been written and playback should stop after playing out all remaining buffers
write
fun write(
buffer: ByteBuffer!,
encodedAccessUnitCount: Int,
presentationTimeUs: Long
): Boolean
Writes audio data to the audio output for playback with a presentation timestamp.
The provided buffer must be a direct byte buffer with native byte order. The method is read-only and will not modify the bytes. It processes data from buffer.position() to buffer.limit() (exclusive). Every call will advance buffer.position() to reflect the number of bytes written.
The first time this method is called with a new buffer, the buffer must contain one or more complete encoded access units or complete PCM frames.
If this method returns false, the same buffer must be used for subsequent calls to this method until it has been fully consumed, or until an intervening call to flush.
| Parameters | |
|---|---|
buffer: ByteBuffer! |
The buffer containing the audio data. |
encodedAccessUnitCount: Int |
The number of encoded access units in the buffer when the buffer was first used in this method, or 1 if the buffer contains PCM audio. When calling this method again after it returned |
presentationTimeUs: Long |
The presentation timestamp, in microseconds, of the first access unit or PCM frame when the buffer was first used in this method. When calling this method again after it returned |
| Returns | |
|---|---|
Boolean |
Whether the buffer was handled fully. |
| Throws | |
|---|---|
androidx.media3.exoplayer.audio.AudioOutput.WriteException |
If the write fails. The audio output cannot be reused after a failure and needs to be recreated. |