ForwardingAudioOutput


@UnstableApi
public class ForwardingAudioOutput implements AudioOutput


A forwarding base class that delegates all calls to the provided AudioOutput.

Summary

Public constructors

Creates the forwarding AudioOutput.

Public methods

void

Adds a Listener for audio output events.

void
attachAuxEffect(int effectId)

Attaches an auxiliary effect to the output.

void

Flushes the audio data from the output.

int

Returns the audio session ID or AUDIO_SESSION_ID_UNSET if unknown.

long

Returns the buffer size in frames of the underlying AudioOutput.

PlaybackParameters

Returns the playback parameters.

long

Returns the current playout timestamp in microseconds.

int

Returns the sample rate of the underlying AudioOutput.

boolean

Returns whether this output is playing back in offload mode.

boolean

Returns whether the audio output is stalled.

void

Pauses playback.

void

Starts or resumes playing audio.

void

Releases the AudioOutput.

void

Removes a Listener for audio output events.

void
setAuxEffectSendLevel(float level)

Sets the send level for the auxiliary effect.

void
setOffloadDelayPadding(int delayInFrames, int paddingInFrames)

Sets the offload delay and padding.

void

Notifies the output that this is the end of the stream.

void

Sets the playback parameters.

void

Sets the PlayerId on the audio output.

void

Sets the preferred audio device for routing.

void
setVolume(float volume)

Sets the volume of the AudioOutput.

void

Signal that the last buffer has been written and playback should stop after playing out all remaining buffers

boolean
write(
    ByteBuffer buffer,
    int encodedAccessUnitCount,
    long presentationTimeUs
)

Writes audio data to the audio output for playback with a presentation timestamp.

Public constructors

ForwardingAudioOutput

public ForwardingAudioOutput(AudioOutput audioOutput)

Creates the forwarding AudioOutput.

Parameters
AudioOutput audioOutput

The wrapped AudioOutput.

Public methods

addListener

public void addListener(AudioOutput.Listener listener)

Adds a Listener for audio output events.

attachAuxEffect

public void attachAuxEffect(int effectId)

Attaches an auxiliary effect to the output.

flush

public void flush()

Flushes the audio data from the output.

getAudioSessionId

public int getAudioSessionId()

Returns the audio session ID or AUDIO_SESSION_ID_UNSET if unknown.

getBufferSizeInFrames

public long getBufferSizeInFrames()

Returns the buffer size in frames of the underlying AudioOutput.

getPlaybackParameters

public PlaybackParameters getPlaybackParameters()

Returns the playback parameters.

getPositionUs

public long getPositionUs()

Returns the current playout timestamp in microseconds.

getSampleRate

public int getSampleRate()

Returns the sample rate of the underlying AudioOutput.

isOffloadedPlayback

public boolean isOffloadedPlayback()

Returns whether this output is playing back in offload mode.

isStalled

public boolean isStalled()

Returns whether the audio output is stalled.

pause

public void pause()

Pauses playback.

play

public void play()

Starts or resumes playing audio.

release

public void release()

Releases the AudioOutput.

removeListener

public void removeListener(AudioOutput.Listener listener)

Removes a Listener for audio output events.

setAuxEffectSendLevel

public void setAuxEffectSendLevel(float level)

Sets the send level for the auxiliary effect.

setOffloadDelayPadding

public void setOffloadDelayPadding(int delayInFrames, int paddingInFrames)

Sets the offload delay and padding.

setOffloadEndOfStream

public void setOffloadEndOfStream()

Notifies the output that this is the end of the stream.

setPlaybackParameters

public void setPlaybackParameters(PlaybackParameters playbackParams)

Sets the playback parameters.

setPlayerId

public void setPlayerId(PlayerId playerId)

Sets the PlayerId on the audio output.

setPreferredDevice

public void setPreferredDevice(@Nullable AudioDeviceInfo preferredDevice)

Sets the preferred audio device for routing.

setVolume

public void setVolume(float volume)

Sets the volume of the AudioOutput.

stop

public void stop()

Signal that the last buffer has been written and playback should stop after playing out all remaining buffers

write

public 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 false, the same number of encoded access units must be provided.

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 false, the same timestamp must be provided.

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.