ForwardingAudioSink
@UnstableApi
class ForwardingAudioSink : AudioSink
CapturingAudioSink |
An |
OggFileAudioBufferSink |
A sink for audio buffers that writes output audio as .ogg files with a given path prefix. |
An overridable AudioSink implementation forwarding all methods to another sink.
Summary
Public constructors |
|---|
ForwardingAudioSink(sink: AudioSink!) |
Public functions |
|
|---|---|
Unit |
Configures (or reconfigures) the sink. |
Unit |
Disables tunneling. |
Unit |
Enables tunneling, if possible. |
Unit |
flush()Flushes the sink, after which it is ready to receive buffers from a new playback position. |
AudioAttributes? |
Returns the audio attributes used for audio playback, or |
Long |
Returns the size of the underlying |
Long |
getCurrentPositionUs(sourceEnded: Boolean)Returns the playback position in the stream starting at zero, in microseconds, or |
AudioOffloadSupport! |
getFormatOffloadSupport(format: Format!)Returns the level of offload support that the sink can provide for a given |
Int |
Returns the level of support that the sink provides for a given |
PlaybackParameters! |
Returns the active |
Boolean |
Returns whether silences are skipped in the audio stream. |
Boolean |
handleBuffer(Attempts to process data from a |
Unit |
Signals to the sink that the next buffer may be discontinuous with the previous buffer. |
Boolean |
Returns whether the sink has data pending that has not been consumed yet. |
Boolean |
isEnded()Returns whether |
Unit |
pause()Pauses playback. |
Unit |
play()Starts or resumes consuming audio if initialized. |
Unit |
Processes any remaining data. |
Unit |
release()Releases the audio sink. |
Unit |
reset()Resets the sink, releasing any resources that it currently holds. |
Unit |
setAudioAttributes(audioAttributes: AudioAttributes!)Sets attributes for audio playback. |
Unit |
setAudioOutputProvider(audioOutputProvider: AudioOutputProvider!)Sets the |
Unit |
setAudioSessionId(audioSessionId: Int)Sets the audio session id. |
Unit |
setAuxEffectInfo(auxEffectInfo: AuxEffectInfo!)Sets the auxiliary effect. |
Unit |
Sets the |
Unit |
setListener(listener: AudioSink.Listener!)Sets the listener for sink events, which should be the audio renderer. |
Unit |
@RequiresApi(value = 29)Sets offload delay padding on the |
Unit |
@RequiresApi(value = 29)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 |
Unit |
setPlaybackParameters(playbackParameters: PlaybackParameters!)Attempts to set the playback parameters. |
Unit |
setPlayerId(playerId: PlayerId?)Sets the |
Unit |
setPreferredDevice(audioDeviceInfo: AudioDeviceInfo?)Sets the preferred audio device. |
Unit |
setSkipSilenceEnabled(skipSilenceEnabled: Boolean)Sets whether silences should be skipped in the audio stream. |
Unit |
setVirtualDeviceId(virtualDeviceId: Int)Sets the virtual device id. |
Unit |
Sets the playback volume. |
Boolean |
supportsFormat(format: Format!)Returns whether the sink supports a given |
Inherited Constants |
||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Public constructors
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 |
| Throws | |
|---|---|
androidx.media3.exoplayer.audio.AudioSink.ConfigurationException |
If an error occurs configuring the sink. |
disableTunneling
fun disableTunneling(): Unit
Disables tunneling. If tunneling was previously enabled then the sink is reset and any audio session id is cleared.
enableTunnelingV21
fun enableTunnelingV21(): Unit
Enables tunneling, if possible. The sink is reset if tunneling was previously disabled. Enabling tunneling is only possible if the sink is based on a platform AudioTrack, and requires platform API version 21 onwards.
| Throws | |
|---|---|
java.lang.IllegalStateException |
Thrown if enabling tunneling on platform API version <21. |
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.
getAudioAttributes
fun getAudioAttributes(): AudioAttributes?
Returns the audio attributes used for audio playback, or null if the sink does not use audio attributes.
getAudioTrackBufferSizeUs
fun getAudioTrackBufferSizeUs(): Long
Returns the size of the underlying AudioTrack buffer in microseconds. If unsupported or the AudioTrack is not initialized then return TIME_UNSET.
If the AudioTrack is configured with a compressed encoding, then the returned duration is an estimated minimum based on the encoding's maximum encoded byte rate.
getCurrentPositionUs
fun getCurrentPositionUs(sourceEnded: Boolean): Long
Returns the playback position in the stream starting at zero, in microseconds, or CURRENT_POSITION_NOT_SET if it is not yet available.
| Parameters | |
|---|---|
sourceEnded: Boolean |
Specify |
| Returns | |
|---|---|
Long |
The playback position relative to the start of playback, in microseconds. |
getFormatOffloadSupport
fun getFormatOffloadSupport(format: Format!): AudioOffloadSupport!
Returns the level of offload support that the sink can provide for a given Format.
| Parameters | |
|---|---|
format: Format! |
The format. |
| Returns | |
|---|---|
AudioOffloadSupport! |
The level of support provided. |
getFormatSupport
@AudioSink.SinkFormatSupport
fun getFormatSupport(format: Format!): Int
Returns the level of support that the sink provides for a given Format.
| Parameters | |
|---|---|
format: Format! |
The format. |
| Returns | |
|---|---|
Int |
The level of support provided. |
getPlaybackParameters
fun getPlaybackParameters(): PlaybackParameters!
Returns the active PlaybackParameters.
getSkipSilenceEnabled
fun getSkipSilenceEnabled(): Boolean
Returns whether silences are skipped in the audio stream.
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.
hasPendingData
fun hasPendingData(): Boolean
Returns whether the sink has data pending that has not been consumed yet.
isEnded
fun isEnded(): Boolean
Returns whether playToEndOfStream has been called and all buffers have been processed.
playToEndOfStream
fun playToEndOfStream(): Unit
Processes any remaining data. isEnded will return true when no data remains.
| Throws | |
|---|---|
androidx.media3.exoplayer.audio.AudioSink.WriteException |
If an error occurs draining data to the sink. |
setAudioAttributes
fun setAudioAttributes(audioAttributes: AudioAttributes!): Unit
Sets attributes for audio playback. If the attributes have changed and if the sink is not configured for use with tunneling, then it is reset and the audio session id is cleared.
If the sink is configured for use with tunneling then the audio attributes are ignored. The sink is not reset and the audio session id is not cleared. The passed attributes will be used if the sink is later re-configured into non-tunneled mode.
| Parameters | |
|---|---|
audioAttributes: AudioAttributes! |
The attributes for audio playback. |
setAudioOutputProvider
fun setAudioOutputProvider(audioOutputProvider: AudioOutputProvider!): Unit
Sets the AudioOutputProvider to use as the output path.
setAuxEffectInfo
fun setAuxEffectInfo(auxEffectInfo: AuxEffectInfo!): Unit
Sets the auxiliary effect.
setListener
fun setListener(listener: AudioSink.Listener!): Unit
Sets the listener for sink events, which should be the audio renderer.
| Parameters | |
|---|---|
listener: AudioSink.Listener! |
The listener for sink events, which should be the audio renderer. |
setOffloadDelayPadding
@RequiresApi(value = 29)
fun setOffloadDelayPadding(delayInFrames: Int, paddingInFrames: Int): Unit
Sets offload delay padding on the AudioTrack, if possible. Setting the offload delay padding is only possible if the sink is based on a platform AudioTrack in offload mode. Also requires platform API version 29 onwards.
setOffloadMode
@RequiresApi(value = 29)
fun setOffloadMode(@AudioSink.OffloadMode offloadMode: Int): Unit
Sets audio offload mode, if possible. Enabling offload is only possible if the sink is based on a platform AudioTrack, and requires platform API version 29 onwards.
setOutputStreamOffsetUs
fun setOutputStreamOffsetUs(outputStreamOffsetUs: Long): Unit
Sets the offset that is added to the media timestamp before it is passed as
presentationTimeUs in handleBuffer.
| Parameters | |
|---|---|
outputStreamOffsetUs: Long |
The output stream offset in microseconds. |
setPlaybackParameters
fun setPlaybackParameters(playbackParameters: PlaybackParameters!): Unit
Attempts to set the playback parameters. The audio sink may override these parameters if they are not supported.
| Parameters | |
|---|---|
playbackParameters: PlaybackParameters! |
The new playback parameters to attempt to set. |
setPlayerId
fun setPlayerId(playerId: PlayerId?): Unit
Sets the PlayerId of the player using this audio sink.
setPreferredDevice
fun setPreferredDevice(audioDeviceInfo: AudioDeviceInfo?): Unit
Sets the preferred audio device.
| Parameters | |
|---|---|
audioDeviceInfo: AudioDeviceInfo? |
The preferred |
setSkipSilenceEnabled
fun setSkipSilenceEnabled(skipSilenceEnabled: Boolean): Unit
Sets whether silences should be skipped in the audio stream.
setVirtualDeviceId
fun setVirtualDeviceId(virtualDeviceId: Int): Unit
Sets the virtual device id.
| Parameters | |
|---|---|
virtualDeviceId: Int |
The |