DecoderAudioRenderer
@UnstableApi
abstract class DecoderAudioRenderer<T : Decoder<DecoderInputBuffer!, SimpleDecoderOutputBuffer!, DecoderException!>?> : BaseRenderer, MediaClock
| kotlin.Any | ||
| ↳ | androidx.media3.exoplayer.BaseRenderer | |
| ↳ | androidx.media3.exoplayer.audio.DecoderAudioRenderer |
Decodes and renders audio using a Decoder.
This renderer accepts the following messages sent via createMessage on the playback thread:
- Message with type
MSG_SET_VOLUMEto set the volume. The message payload should be aFloatwith 0 being silence and 1 being unity gain. - Message with type
MSG_SET_AUDIO_ATTRIBUTESto set the audio attributes. The message payload should be anAudioAttributesinstance that will configure the underlying audio track. - Message with type
MSG_SET_AUX_EFFECT_INFOto set the auxiliary effect. The message payload should be anAuxEffectInfoinstance that will configure the underlying audio track. - Message with type
MSG_SET_PREFERRED_AUDIO_DEVICEto set the preferred audio output device. The message payload should be anAudioDeviceInfoinstance. - Message with type
MSG_SET_VIRTUAL_DEVICE_IDto set the virtual device id. The message payload should be anIntegerfor the virtual device id orINDEX_UNSETif unspecified. - Message with type
MSG_SET_SKIP_SILENCE_ENABLEDto enable or disable skipping silences. The message payload should be aBoolean. - Message with type
MSG_SET_AUDIO_SESSION_IDto set the audio session ID. The message payload should be a session IDIntegerthat will be attached to the underlying audio track. - Message with type
MSG_SET_AUDIO_OUTPUT_PROVIDERto set the audio output provider. The message payload must be anAudioOutputProviderinstance.
Summary
Public constructors |
|---|
DecoderAudioRenderer( |
DecoderAudioRenderer( |
DecoderAudioRenderer( |
Public functions |
|
|---|---|
Long |
getDurationToProgressUs(positionUs: Long, elapsedRealtimeUs: Long)Returns minimum amount of playback clock time that must pass in order for the |
MediaClock? |
If the renderer advances its own playback position then this method returns a corresponding |
PlaybackParameters! |
Returns the active playback parameters. |
Long |
Returns the current media position in microseconds. |
Unit |
handleMessage(@Renderer.MessageType messageType: Int, message: Any?)Handles a message delivered to the target. |
Boolean |
Returns whether there is a skipped silence since the last call to this method. |
Boolean |
isEnded()Whether the renderer is ready for the |
Boolean |
isReady()Whether the renderer is able to immediately render media from the current position. |
Unit |
Incrementally renders the |
Unit |
setPlaybackParameters(playbackParameters: PlaybackParameters!)Attempts to set the playback parameters. |
Int |
Returns the extent to which the |
Protected functions |
|
|---|---|
DecoderReuseEvaluation! |
@ForOverrideEvaluates whether the existing decoder can be reused for a new |
abstract T! |
@ForOverrideCreates a decoder for the given format. |
IntArray<Int>? |
@ForOverrideReturns the channel layout mapping that should be applied when sending this data to the output, or null to not change the channel layout. |
abstract Format! |
@ForOverrideReturns the format of audio buffers output by the decoder. |
Int |
Returns the level of support that the renderer's |
Boolean |
Returns whether the renderer is ready to start or continue decoding. |
Unit |
Called when the renderer is disabled. |
Unit |
Called when the renderer is enabled. |
Unit |
|
Unit |
onPositionReset(Called when the position is reset. |
Unit |
Called when the renderer is started. |
Unit |
Called when the renderer is stopped. |
Unit |
onStreamChanged(Called when the renderer's stream has changed. |
Boolean |
sinkSupportsFormat(format: Format!)Returns whether the renderer's |
abstract Int |
Returns the |
Inherited Constants |
||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Inherited functions |
||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
Inherited properties |
|---|
Public constructors
DecoderAudioRenderer
DecoderAudioRenderer(
eventHandler: Handler?,
eventListener: AudioRendererEventListener?,
audioProcessors: Array<AudioProcessor!>!
)
| Parameters | |
|---|---|
eventHandler: Handler? |
A handler to use when delivering events to |
eventListener: AudioRendererEventListener? |
A listener of events. May be null if delivery of events is not required. |
audioProcessors: Array<AudioProcessor!>! |
Optional |
DecoderAudioRenderer
DecoderAudioRenderer(
eventHandler: Handler?,
eventListener: AudioRendererEventListener?,
audioSink: AudioSink!
)
| Parameters | |
|---|---|
eventHandler: Handler? |
A handler to use when delivering events to |
eventListener: AudioRendererEventListener? |
A listener of events. May be null if delivery of events is not required. |
audioSink: AudioSink! |
The sink to which audio will be output. |
DecoderAudioRenderer
DecoderAudioRenderer(
eventHandler: Handler?,
eventListener: AudioRendererEventListener?,
audioCapabilities: AudioCapabilities!,
audioProcessors: Array<AudioProcessor!>!
)
| Parameters | |
|---|---|
eventHandler: Handler? |
A handler to use when delivering events to |
eventListener: AudioRendererEventListener? |
A listener of events. May be null if delivery of events is not required. |
audioCapabilities: AudioCapabilities! |
The audio capabilities for playback on this device. Use |
audioProcessors: Array<AudioProcessor!>! |
Optional |
Public functions
getDurationToProgressUs
fun getDurationToProgressUs(positionUs: Long, elapsedRealtimeUs: Long): Long
Returns minimum amount of playback clock time that must pass in order for the render call to make progress.
This method may be called when the renderer is in the following states: STATE_ENABLED, STATE_STARTED.
The default return time is DEFAULT_DURATION_TO_PROGRESS_US if the renderer is in STATE_STARTED, or in STATE_ENABLED and not yet ready or ended. Otherwise, it returns DEFAULT_IDLE_DURATION_TO_PROGRESS_US.
| Parameters | |
|---|---|
positionUs: Long |
The current render position in microseconds, measured at the start of the current iteration of the rendering loop. |
elapsedRealtimeUs: Long |
|
| Returns | |
|---|---|
Long |
Minimum amount of playback clock time that must pass before renderer is able to make progress. |
getMediaClock
fun getMediaClock(): MediaClock?
If the renderer advances its own playback position then this method returns a corresponding MediaClock. If provided, the player will use the returned MediaClock as its source of time during playback. A player may have at most one renderer that returns a MediaClock from this method.
| Returns | |
|---|---|
MediaClock? |
The |
getPlaybackParameters
fun getPlaybackParameters(): PlaybackParameters!
Returns the active playback parameters.
handleMessage
fun handleMessage(@Renderer.MessageType messageType: Int, message: Any?): Unit
Handles a message delivered to the target.
| Parameters | |
|---|---|
@Renderer.MessageType messageType: Int |
The message type. |
message: Any? |
The message payload. |
| Throws | |
|---|---|
androidx.media3.exoplayer.ExoPlaybackException |
If an error occurred whilst handling the message. Should only be thrown by targets that handle messages on the playback thread. |
hasSkippedSilenceSinceLastCall
fun hasSkippedSilenceSinceLastCall(): Boolean
Returns whether there is a skipped silence since the last call to this method.
isEnded
fun isEnded(): Boolean
Whether the renderer is ready for the ExoPlayer instance to transition to STATE_ENDED. The player will make this transition as soon as true is returned by all of its renderers.
This method may be called when the renderer is in the following states: STATE_ENABLED, STATE_STARTED.
| Returns | |
|---|---|
Boolean |
Whether the renderer is ready for the player to transition to the ended state. |
isReady
fun isReady(): Boolean
Whether the renderer is able to immediately render media from the current position.
If the renderer is in the STATE_STARTED state then returning true indicates that the renderer has everything that it needs to continue playback. Returning false indicates that the player should pause until the renderer is ready.
If the renderer is in the STATE_ENABLED state then returning true indicates that the renderer is ready for playback to be started. Returning false indicates that it is not.
This method may be called when the renderer is in the following states: STATE_ENABLED, STATE_STARTED.
| Returns | |
|---|---|
Boolean |
Whether the renderer is ready to render media. |
render
fun render(positionUs: Long, elapsedRealtimeUs: Long): Unit
Incrementally renders the SampleStream.
If the renderer is in the STATE_ENABLED state then each call to this method will do work toward being ready to render the SampleStream when the renderer is started. If the renderer is in the STATE_STARTED state then calls to this method will render the SampleStream in sync with the specified media positions.
The renderer may also render the very start of the media at the current position (e.g. the first frame of a video stream) while still in the STATE_ENABLED state, unless it's the initial start of the media after calling enable with
mayRenderStartOfStream set to false.
This method should return quickly, and should not block if the renderer is unable to make useful progress.
This method may be called when the renderer is in the following states: STATE_ENABLED, STATE_STARTED.
| Parameters | |
|---|---|
positionUs: Long |
The current media time in microseconds, measured at the start of the current iteration of the rendering loop. |
elapsedRealtimeUs: Long |
|
| Throws | |
|---|---|
androidx.media3.exoplayer.ExoPlaybackException |
If an error occurs. |
setPlaybackParameters
fun setPlaybackParameters(playbackParameters: PlaybackParameters!): Unit
Attempts to set the playback parameters. The media clock may override the speed if changing the playback parameters is not supported.
| Parameters | |
|---|---|
playbackParameters: PlaybackParameters! |
The playback parameters to attempt to set. |
supportsFormat
@RendererCapabilities.Capabilities
fun supportsFormat(format: Format!): Int
Returns the extent to which the Renderer supports a given format.
| Parameters | |
|---|---|
format: Format! |
The format. |
| Returns | |
|---|---|
Int |
The |
| Throws | |
|---|---|
androidx.media3.exoplayer.ExoPlaybackException |
If an error occurs. |
Protected functions
canReuseDecoder
@ForOverride
protected fun canReuseDecoder(decoderName: String!, oldFormat: Format!, newFormat: Format!): DecoderReuseEvaluation!
Evaluates whether the existing decoder can be reused for a new Format.
The default implementation does not allow decoder reuse.
| Parameters | |
|---|---|
decoderName: String! |
The name of the decoder. |
oldFormat: Format! |
The previous format. |
newFormat: Format! |
The new format. |
| Returns | |
|---|---|
DecoderReuseEvaluation! |
The result of the evaluation. |
createDecoder
@ForOverride
protected abstract fun createDecoder(format: Format!, cryptoConfig: CryptoConfig?): T!
Creates a decoder for the given format.
| Parameters | |
|---|---|
format: Format! |
The format for which a decoder is required. |
cryptoConfig: CryptoConfig? |
The |
| Returns | |
|---|---|
T! |
The decoder. |
| Throws | |
|---|---|
androidx.media3.decoder.DecoderException |
If an error occurred creating a suitable decoder. |
getChannelMapping
@ForOverride
protected fun getChannelMapping(decoder: T!): IntArray<Int>?
Returns the channel layout mapping that should be applied when sending this data to the output, or null to not change the channel layout.
| Parameters | |
|---|---|
decoder: T! |
The decoder. |
getOutputFormat
@ForOverride
protected abstract fun getOutputFormat(decoder: T!): Format!
Returns the format of audio buffers output by the decoder. Will not be called until the first output buffer has been dequeued, so the decoder may use input data to determine the format.
| Parameters | |
|---|---|
decoder: T! |
The decoder. |
getSinkFormatSupport
@AudioSink.SinkFormatSupport
protected fun getSinkFormatSupport(format: Format!): Int
Returns the level of support that the renderer's AudioSink provides for a given Format.
| See also | |
|---|---|
getFormatSupport |
(Format) |
isReadyForDecoding
protected fun isReadyForDecoding(): Boolean
Returns whether the renderer is ready to start or continue decoding.
onDisabled
protected fun onDisabled(): Unit
Called when the renderer is disabled.
The default implementation is a no-op.
onEnabled
protected fun onEnabled(joining: Boolean, mayRenderStartOfStream: Boolean): Unit
Called when the renderer is enabled.
The default implementation is a no-op.
| Parameters | |
|---|---|
joining: Boolean |
Whether this renderer is being enabled to join an ongoing playback. |
mayRenderStartOfStream: Boolean |
Whether this renderer is allowed to render the start of the stream even if the state is not |
| Throws | |
|---|---|
androidx.media3.exoplayer.ExoPlaybackException |
If an error occurs. |
onPositionReset
protected fun onPositionReset(
positionUs: Long,
joining: Boolean,
sampleStreamIsResetToKeyFrame: Boolean
): Unit
Called when the position is reset. This occurs when the renderer is enabled after onStreamChanged has been called, and also when a position discontinuity is encountered.
After a position reset, the renderer's SampleStream is guaranteed to provide samples starting from a key frame if sampleStreamIsResetToKeyFrame is true.
sampleStreamIsResetToKeyFrame is guaranteed to be true unless the implementation overrides supportsResetPositionWithoutKeyFrameReset to return
true.
The default implementation is a no-op.
| Parameters | |
|---|---|
positionUs: Long |
The new playback position in microseconds. |
joining: Boolean |
Whether this renderer is being enabled to join an ongoing playback. |
sampleStreamIsResetToKeyFrame: Boolean |
Whether the renderer's |
| Throws | |
|---|---|
androidx.media3.exoplayer.ExoPlaybackException |
If an error occurs. |
onStarted
protected fun onStarted(): Unit
Called when the renderer is started.
The default implementation is a no-op.
| Throws | |
|---|---|
androidx.media3.exoplayer.ExoPlaybackException |
If an error occurs. |
onStopped
protected fun onStopped(): Unit
Called when the renderer is stopped.
The default implementation is a no-op.
onStreamChanged
protected fun onStreamChanged(
formats: Array<Format!>!,
startPositionUs: Long,
offsetUs: Long,
mediaPeriodId: MediaSource.MediaPeriodId!
): Unit
Called when the renderer's stream has changed. This occurs when the renderer is enabled after onEnabled has been called, and also when the stream has been replaced whilst the renderer is enabled or started.
The default implementation is a no-op.
| Parameters | |
|---|---|
formats: Array<Format!>! |
The enabled formats. |
startPositionUs: Long |
The start position of the new stream in renderer time (microseconds). |
offsetUs: Long |
The offset that will be added to the timestamps of buffers read via |
mediaPeriodId: MediaSource.MediaPeriodId! |
The |
| Throws | |
|---|---|
androidx.media3.exoplayer.ExoPlaybackException |
If an error occurs. |
sinkSupportsFormat
protected fun sinkSupportsFormat(format: Format!): Boolean
Returns whether the renderer's AudioSink supports a given Format.
| See also | |
|---|---|
supportsFormat |
supportsFormatInternal
@ForOverride
@C.FormatSupport
protected abstract fun supportsFormatInternal(format: Format!): Int
Returns the C.FormatSupport for the given Format.
| Parameters | |
|---|---|
format: Format! |
The format, which has an audio |
| Returns | |
|---|---|
Int |
The |