AudioOutput
public 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 |
|---|
public interface AudioOutput.ListenerListener for |
public final class AudioOutput.WriteException extends ExceptionThrown when a failure occurs writing to the output. |
Public methods |
|
|---|---|
abstract void |
addListener(AudioOutput.Listener listener)Adds a |
abstract void |
attachAuxEffect(int effectId)Attaches an auxiliary effect to the output. |
default boolean |
@UnstableApiReturns if the configurations are sufficiently compatible to reuse this audio output. |
abstract void |
flush()Flushes the audio data from the output. |
abstract int |
Returns the audio session ID or |
abstract long |
Returns the buffer size in frames of the underlying |
abstract PlaybackParameters |
Returns the playback parameters. |
abstract long |
Returns the current playout timestamp in microseconds. |
abstract int |
Returns the sample rate of the underlying |
abstract boolean |
Returns whether this output is playing back in offload mode. |
abstract boolean |
Returns whether the audio output is stalled. |
abstract void |
pause()Pauses playback. |
abstract void |
play()Starts or resumes playing audio. |
abstract void |
release()Releases the |
abstract void |
removeListener(AudioOutput.Listener listener)Removes a |
abstract void |
setAuxEffectSendLevel(float level)Sets the send level for the auxiliary effect. |
abstract void |
setOffloadDelayPadding(int delayInFrames, int paddingInFrames)Sets the offload delay and padding. |
abstract void |
Notifies the output that this is the end of the stream. |
abstract void |
setPlaybackParameters(PlaybackParameters playbackParams)Sets the playback parameters. |
default void |
@UnstableApiSets the |
abstract void |
setPreferredDevice(@Nullable AudioDeviceInfo preferredDevice)Sets the preferred audio device for routing, or null for no preference. |
abstract void |
setVolume(float volume)Sets the volume of the |
abstract void |
stop()Signal that the last buffer has been written and playback should stop after playing out all remaining buffers |
abstract boolean |
write(Writes audio data to the audio output for playback with a presentation timestamp. |
Public methods
addListener
abstract void addListener(AudioOutput.Listener listener)
Adds a Listener for audio output events.
attachAuxEffect
abstract void attachAuxEffect(int effectId)
Attaches an auxiliary effect to the output.
canReuseAudioOutput
@UnstableApi
default boolean canReuseAudioOutput(
AudioOutputProvider.OutputConfig currentConfig,
AudioOutputProvider.FormatConfig newFormat,
AudioOutputProvider.OutputConfig newConfig
)
Returns if the configurations are sufficiently compatible to reuse this audio output.
getAudioSessionId
abstract int getAudioSessionId()
Returns the audio session ID or AUDIO_SESSION_ID_UNSET if unknown.
getBufferSizeInFrames
abstract long getBufferSizeInFrames()
Returns the buffer size in frames of the underlying AudioOutput.
getPlaybackParameters
abstract PlaybackParameters getPlaybackParameters()
Returns the playback parameters.
isOffloadedPlayback
abstract boolean isOffloadedPlayback()
Returns whether this output is playing back in offload mode.
removeListener
abstract void removeListener(AudioOutput.Listener listener)
Removes a Listener for audio output events.
setAuxEffectSendLevel
abstract void setAuxEffectSendLevel(float level)
Sets the send level for the auxiliary effect.
setOffloadDelayPadding
abstract void setOffloadDelayPadding(int delayInFrames, int paddingInFrames)
Sets the offload delay and padding.
setOffloadEndOfStream
abstract void setOffloadEndOfStream()
Notifies the output that this is the end of the stream.
setPlaybackParameters
abstract void setPlaybackParameters(PlaybackParameters playbackParams)
Sets the playback parameters.
setPlayerId
@UnstableApi
default void setPlayerId(PlayerId playerId)
Sets the PlayerId on the audio output.
setPreferredDevice
abstract void setPreferredDevice(@Nullable AudioDeviceInfo preferredDevice)
Sets the preferred audio device for routing, or null for no preference.
stop
abstract void stop()
Signal that the last buffer has been written and playback should stop after playing out all remaining buffers
write
abstract boolean write(
ByteBuffer buffer,
int encodedAccessUnitCount,
long presentationTimeUs
)
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 | |
|---|---|
ByteBuffer buffer |
The buffer containing the audio data. |
int encodedAccessUnitCount |
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 |
long presentationTimeUs |
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. |