CapturingAudioSink


@UnstableApi
class CapturingAudioSink : ForwardingAudioSink, Dumper.Dumpable


A ForwardingAudioSink that captures configuration, discontinuity and buffer events.

Summary

Public constructors

Public functions

Unit
configure(
    inputFormat: Format!,
    specifiedBufferSize: Int,
    outputChannels: IntArray?
)

Configures (or reconfigures) the sink.

Unit
dump(dumper: Dumper!)

Dumps the fields of the object using the dumper.

Unit

Flushes the sink, after which it is ready to receive buffers from a new playback position.

Boolean
handleBuffer(
    buffer: ByteBuffer!,
    presentationTimeUs: Long,
    encodedAccessUnitCount: Int
)

Attempts to process data from a ByteBuffer, starting from its current position and ending at its limit (exclusive).

Unit

Signals to the sink that the next buffer may be discontinuous with the previous buffer.

Unit

Resets the sink, releasing any resources that it currently holds.

Inherited Constants

From androidx.media3.exoplayer.audio.AudioSink
const Long
CURRENT_POSITION_NOT_SET = -9223372036854775808

Returned by getCurrentPositionUs when the position is not set.

const Int

The audio sink will never play in offload mode.

const Int

The audio sink will prefer offload playback even if this might result in silence gaps between tracks.

const Int

The audio sink will prefer offload playback except in the case where both the track is gapless and the device does support gapless offload playback.

const Int

The sink supports the format directly, without the need for internal transcoding.

const Int

The sink supports the format, but needs to transcode it internally to do so.

const Int

The sink does not support the format.

Inherited functions

From androidx.media3.exoplayer.audio.AudioSink
abstract Boolean
handleBuffer(
    buffer: ByteBuffer!,
    presentationTimeUs: Long,
    encodedAccessUnitCount: Int
)

Attempts to process data from a ByteBuffer, starting from its current position and ending at its limit (exclusive).

From androidx.media3.exoplayer.audio.ForwardingAudioSink
Unit

Disables tunneling.

Unit

Enables tunneling, if possible.

AudioAttributes?

Returns the audio attributes used for audio playback, or null if the sink does not use audio attributes.

Long

Returns the playback position in the stream starting at zero, in microseconds, or CURRENT_POSITION_NOT_SET if it is not yet available.

AudioOffloadSupport!

Returns the level of offload support that the sink can provide for a given Format.

Int

Returns the level of support that the sink provides for a given Format.

PlaybackParameters!

Returns the active PlaybackParameters.

Boolean

Returns whether silences are skipped in the audio stream.

Boolean

Returns whether the sink has data pending that has not been consumed yet.

Boolean

Returns whether playToEndOfStream has been called and all buffers have been processed.

Unit

Pauses playback.

Unit

Starts or resumes consuming audio if initialized.

Unit

Processes any remaining data.

Unit

Releases the audio sink.

Unit

Sets attributes for audio playback.

Unit
setAudioSessionId(audioSessionId: Int)

Sets the audio session id.

Unit

Sets the auxiliary effect.

Unit
setClock(clock: Clock!)

Sets the Clock to use for timing in this audio sink.

Unit

Sets the listener for sink events, which should be the audio renderer.

Unit
@RequiresApi(value = 29)
setOffloadDelayPadding(delayInFrames: Int, paddingInFrames: Int)

Sets offload delay padding on the AudioTrack, if possible.

Unit
@RequiresApi(value = 29)
setOffloadMode(@AudioSink.OffloadMode offloadMode: Int)

Sets audio offload mode, if possible.

Unit
setOutputStreamOffsetUs(outputStreamOffsetUs: Long)

Sets the offset that is added to the media timestamp before it is passed as presentationTimeUs in handleBuffer.

Unit

Attempts to set the playback parameters.

Unit
setPlayerId(playerId: PlayerId?)

Sets the PlayerId of the player using this audio sink.

Unit
@RequiresApi(value = 23)
setPreferredDevice(audioDeviceInfo: AudioDeviceInfo?)

Sets the preferred audio device.

Unit
setSkipSilenceEnabled(skipSilenceEnabled: Boolean)

Sets whether silences should be skipped in the audio stream.

Unit
setVolume(volume: Float)

Sets the playback volume.

Boolean

Returns whether the sink supports a given Format.

Public constructors

CapturingAudioSink

CapturingAudioSink(sink: AudioSink!)

Public functions

configure

fun configure(
    inputFormat: Format!,
    specifiedBufferSize: Int,
    outputChannels: IntArray?
): Unit

Configures (or reconfigures) the sink.

Parameters
inputFormat: Format!

The format of audio data provided in the input buffers.

specifiedBufferSize: Int

A specific size for the playback buffer in bytes, or 0 to infer a suitable buffer size.

outputChannels: IntArray?

A mapping from input to output channels that is applied to this sink's input as a preprocessing step, if handling PCM input. Specify null to leave the input unchanged. Otherwise, the element at index i specifies index of the input channel to map to output channel i when preprocessing input buffers. After the map is applied the audio data will have outputChannels.length channels.

Throws
androidx.media3.exoplayer.audio.AudioSink.ConfigurationException

If an error occurs configuring the sink.

dump

fun dump(dumper: Dumper!): Unit

Dumps the fields of the object using the dumper.

Parameters
dumper: Dumper!

The Dumper to be used to dump fields.

flush

fun flush(): Unit

Flushes the sink, after which it is ready to receive buffers from a new playback position.

The audio session may remain active until reset is called.

handleBuffer

fun handleBuffer(
    buffer: ByteBuffer!,
    presentationTimeUs: Long,
    encodedAccessUnitCount: Int
): Boolean

Attempts to process data from a ByteBuffer, starting from its current position and ending at its limit (exclusive). The position of the ByteBuffer is advanced by the number of bytes that were handled. onPositionDiscontinuity will be called if presentationTimeUs is discontinuous with the last buffer handled since the last reset.

Returns whether the data was handled in full. If the data was not handled in full then the same ByteBuffer must be provided to subsequent calls until it has been fully consumed, except in the case of an intervening call to flush (or to configure that causes the sink to be flushed).

Parameters
buffer: ByteBuffer!

The buffer containing audio data.

presentationTimeUs: Long

The presentation timestamp of the buffer in microseconds.

encodedAccessUnitCount: Int

The number of encoded access units in the buffer, or 1 if the buffer contains PCM audio. This allows batching multiple encoded access units in one buffer.

Returns
Boolean

Whether the buffer was handled fully.

Throws
androidx.media3.exoplayer.audio.AudioSink.InitializationException

If an error occurs initializing the sink.

androidx.media3.exoplayer.audio.AudioSink.WriteException

If an error occurs writing the audio data.

handleDiscontinuity

fun handleDiscontinuity(): Unit

Signals to the sink that the next buffer may be discontinuous with the previous buffer.

reset

fun reset(): Unit

Resets the sink, releasing any resources that it currently holds.