Class DecoderAudioRenderer<T extends Decoder<DecoderInputBuffer,​? extends SimpleDecoderOutputBuffer,​? extends DecoderException>>

    • Constructor Detail

      • DecoderAudioRenderer

        public DecoderAudioRenderer()
      • DecoderAudioRenderer

        public DecoderAudioRenderer​(@Nullable
                                    Handler eventHandler,
                                    @Nullable
                                    AudioRendererEventListener eventListener,
                                    AudioProcessor... audioProcessors)
        Parameters:
        eventHandler - A handler to use when delivering events to eventListener. May be null if delivery of events is not required.
        eventListener - A listener of events. May be null if delivery of events is not required.
        audioProcessors - Optional AudioProcessors that will process audio before output.
      • DecoderAudioRenderer

        public DecoderAudioRenderer​(@Nullable
                                    Handler eventHandler,
                                    @Nullable
                                    AudioRendererEventListener eventListener,
                                    AudioCapabilities audioCapabilities,
                                    AudioProcessor... audioProcessors)
        Parameters:
        eventHandler - A handler to use when delivering events to eventListener. May be null if delivery of events is not required.
        eventListener - A listener of events. May be null if delivery of events is not required.
        audioCapabilities - The audio capabilities for playback on this device. Use AudioCapabilities.DEFAULT_AUDIO_CAPABILITIES if default capabilities (no encoded audio passthrough support) should be assumed.
        audioProcessors - Optional AudioProcessors that will process audio before output.
      • DecoderAudioRenderer

        public DecoderAudioRenderer​(@Nullable
                                    Handler eventHandler,
                                    @Nullable
                                    AudioRendererEventListener eventListener,
                                    AudioSink audioSink)
        Parameters:
        eventHandler - A handler to use when delivering events to eventListener. May be null if delivery of events is not required.
        eventListener - A listener of events. May be null if delivery of events is not required.
        audioSink - The sink to which audio will be output.
    • Method Detail

      • experimentalSetEnableKeepAudioTrackOnSeek

        public void experimentalSetEnableKeepAudioTrackOnSeek​(boolean enableKeepAudioTrackOnSeek)
        Sets whether to enable the experimental feature that keeps and flushes the AudioTrack when a seek occurs, as opposed to releasing and reinitialising. Off by default.

        This method is experimental, and will be renamed or removed in a future release.

        Parameters:
        enableKeepAudioTrackOnSeek - Whether to keep the AudioTrack on seek.
      • getMediaClock

        @Nullable
        public MediaClock getMediaClock()
        Description copied from interface: Renderer
        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.
        Specified by:
        getMediaClock in interface Renderer
        Overrides:
        getMediaClock in class BaseRenderer
        Returns:
        The MediaClock tracking the playback position of the renderer, or null.
      • getSinkFormatSupport

        protected final @com.google.android.exoplayer2.audio.AudioSink.SinkFormatSupport int getSinkFormatSupport​(Format format)
        Returns the level of support that the renderer's AudioSink provides for a given Format.
        See Also:
        (Format)
      • createDecoder

        protected abstract T createDecoder​(Format format,
                                           @Nullable
                                           CryptoConfig cryptoConfig)
                                    throws DecoderException
        Creates a decoder for the given format.
        Parameters:
        format - The format for which a decoder is required.
        cryptoConfig - The CryptoConfig object required for decoding encrypted content. May be null and can be ignored if decoder does not handle encrypted content.
        Returns:
        The decoder.
        Throws:
        DecoderException - If an error occurred creating a suitable decoder.
      • getOutputFormat

        protected abstract Format getOutputFormat​(T decoder)
        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 - The decoder.
      • canReuseDecoder

        protected DecoderReuseEvaluation canReuseDecoder​(String decoderName,
                                                         Format oldFormat,
                                                         Format newFormat)
        Evaluates whether the existing decoder can be reused for a new Format.

        The default implementation does not allow decoder reuse.

        Parameters:
        decoderName - The name of the decoder.
        oldFormat - The previous format.
        newFormat - The new format.
        Returns:
        The result of the evaluation.
      • isEnded

        public boolean isEnded()
        Description copied from interface: Renderer
        Whether the renderer is ready for the ExoPlayer instance to transition to Player.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: Renderer.STATE_ENABLED, Renderer.STATE_STARTED.

        Specified by:
        isEnded in interface Renderer
        Returns:
        Whether the renderer is ready for the player to transition to the ended state.
      • isReady

        public boolean isReady()
        Description copied from interface: Renderer
        Whether the renderer is able to immediately render media from the current position.

        If the renderer is in the Renderer.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 Renderer.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: Renderer.STATE_ENABLED, Renderer.STATE_STARTED.

        Specified by:
        isReady in interface Renderer
        Returns:
        Whether the renderer is ready to render media.
      • getPositionUs

        public long getPositionUs()
        Description copied from interface: MediaClock
        Returns the current media position in microseconds.
        Specified by:
        getPositionUs in interface MediaClock
      • setPlaybackParameters

        public void setPlaybackParameters​(PlaybackParameters playbackParameters)
        Description copied from interface: MediaClock
        Attempts to set the playback parameters. The media clock may override the speed if changing the playback parameters is not supported.
        Specified by:
        setPlaybackParameters in interface MediaClock
        Parameters:
        playbackParameters - The playback parameters to attempt to set.
      • onEnabled

        protected void onEnabled​(boolean joining,
                                 boolean mayRenderStartOfStream)
                          throws ExoPlaybackException
        Description copied from class: BaseRenderer
        Called when the renderer is enabled.

        The default implementation is a no-op.

        Overrides:
        onEnabled in class BaseRenderer
        Parameters:
        joining - Whether this renderer is being enabled to join an ongoing playback.
        mayRenderStartOfStream - Whether this renderer is allowed to render the start of the stream even if the state is not Renderer.STATE_STARTED yet.
        Throws:
        ExoPlaybackException - If an error occurs.
      • onPositionReset

        protected void onPositionReset​(long positionUs,
                                       boolean joining)
                                throws ExoPlaybackException
        Description copied from class: BaseRenderer
        Called when the position is reset. This occurs when the renderer is enabled after BaseRenderer.onStreamChanged(Format[], long, long) 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.

        The default implementation is a no-op.

        Overrides:
        onPositionReset in class BaseRenderer
        Parameters:
        positionUs - The new playback position in microseconds.
        joining - Whether this renderer is being enabled to join an ongoing playback.
        Throws:
        ExoPlaybackException - If an error occurs.
      • onStarted

        protected void onStarted()
        Description copied from class: BaseRenderer
        Called when the renderer is started.

        The default implementation is a no-op.

        Overrides:
        onStarted in class BaseRenderer
      • onStopped

        protected void onStopped()
        Description copied from class: BaseRenderer
        Called when the renderer is stopped.

        The default implementation is a no-op.

        Overrides:
        onStopped in class BaseRenderer
      • onDisabled

        protected void onDisabled()
        Description copied from class: BaseRenderer
        Called when the renderer is disabled.

        The default implementation is a no-op.

        Overrides:
        onDisabled in class BaseRenderer