Package com.google.android.exoplayer2

## Class DefaultRenderersFactory

- java.lang.Object
- - com.google.android.exoplayer2.DefaultRenderersFactory

- All Implemented Interfaces:
    `RenderersFactory`

      public class DefaultRenderersFactory
      extends Object
      implements RenderersFactory

  Default `RenderersFactory` implementation.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class | Description
    --- | --- | ---
    `static interface` | `DefaultRenderersFactory.ExtensionRendererMode` | Modes for using extension renderers.

  - ### Field Summary

    Fields
    Modifier and Type | Field | Description
    --- | --- | ---
    `static long` | `DEFAULT_ALLOWED_VIDEO_JOINING_TIME_MS` | The default maximum duration for which a video renderer can attempt to seamlessly join an ongoing playback.
    `static int` | `EXTENSION_RENDERER_MODE_OFF` | Do not allow use of extension renderers.
    `static int` | `EXTENSION_RENDERER_MODE_ON` | Allow use of extension renderers.
    `static int` | `EXTENSION_RENDERER_MODE_PREFER` | Allow use of extension renderers.
    `static int` | `MAX_DROPPED_VIDEO_FRAME_COUNT_TO_NOTIFY` | The maximum number of frames that can be dropped between invocations of `VideoRendererEventListener.onDroppedFrames(int, long)`.

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `DefaultRenderersFactory​(Context context)` |

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `protected void` | `buildAudioRenderers​(Context context, @com.google.android.exoplayer2.DefaultRenderersFactory.ExtensionRendererMode int extensionRendererMode, MediaCodecSelector mediaCodecSelector, boolean enableDecoderFallback, AudioSink audioSink, Handler eventHandler, AudioRendererEventListener eventListener, ArrayList<Renderer> out)` | Builds audio renderers for use by the player.
    `protected AudioSink` | `buildAudioSink​(Context context, boolean enableFloatOutput, boolean enableAudioTrackPlaybackParams, boolean enableOffload)` | Builds an `AudioSink` to which the audio renderers will output.
    `protected void` | `buildCameraMotionRenderers​(Context context, @com.google.android.exoplayer2.DefaultRenderersFactory.ExtensionRendererMode int extensionRendererMode, ArrayList<Renderer> out)` | Builds camera motion renderers for use by the player.
    `protected void` | `buildMetadataRenderers​(Context context, MetadataOutput output, Looper outputLooper, @com.google.android.exoplayer2.DefaultRenderersFactory.ExtensionRendererMode int extensionRendererMode, ArrayList<Renderer> out)` | Builds metadata renderers for use by the player.
    `protected void` | `buildMiscellaneousRenderers​(Context context, Handler eventHandler, @com.google.android.exoplayer2.DefaultRenderersFactory.ExtensionRendererMode int extensionRendererMode, ArrayList<Renderer> out)` | Builds any miscellaneous renderers used by the player.
    `protected void` | `buildTextRenderers​(Context context, TextOutput output, Looper outputLooper, @com.google.android.exoplayer2.DefaultRenderersFactory.ExtensionRendererMode int extensionRendererMode, ArrayList<Renderer> out)` | Builds text renderers for use by the player.
    `protected void` | `buildVideoRenderers​(Context context, @com.google.android.exoplayer2.DefaultRenderersFactory.ExtensionRendererMode int extensionRendererMode, MediaCodecSelector mediaCodecSelector, boolean enableDecoderFallback, Handler eventHandler, VideoRendererEventListener eventListener, long allowedVideoJoiningTimeMs, ArrayList<Renderer> out)` | Builds video renderers for use by the player.
    `Renderer[]` | `createRenderers​(Handler eventHandler, VideoRendererEventListener videoRendererEventListener, AudioRendererEventListener audioRendererEventListener, TextOutput textRendererOutput, MetadataOutput metadataRendererOutput)` | Builds the `Renderer` instances for an `ExoPlayer`.
    `DefaultRenderersFactory` | `experimentalSetSynchronizeCodecInteractionsWithQueueingEnabled​(boolean enabled)` | Enable synchronizing codec interactions with asynchronous buffer queueing.
    `DefaultRenderersFactory` | `forceDisableMediaCodecAsynchronousQueueing()` | Disables `MediaCodecRenderer` instances from operating their `MediaCodec` in asynchronous mode and perform asynchronous queueing.
    `DefaultRenderersFactory` | `forceEnableMediaCodecAsynchronousQueueing()` | Enables `MediaCodecRenderer` instances to operate their `MediaCodec` in asynchronous mode and perform asynchronous queueing.
    `protected MediaCodecAdapter.Factory` | `getCodecAdapterFactory()` | Returns the `MediaCodecAdapter.Factory` that will be used when creating `MediaCodecRenderer` instances.
    `DefaultRenderersFactory` | `setAllowedVideoJoiningTimeMs​(long allowedVideoJoiningTimeMs)` | Sets the maximum duration for which video renderers can attempt to seamlessly join an ongoing playback.
    `DefaultRenderersFactory` | `setEnableAudioFloatOutput​(boolean enableFloatOutput)` | Sets whether floating point audio should be output when possible.
    `DefaultRenderersFactory` | `setEnableAudioOffload​(boolean enableOffload)` | Sets whether audio should be played using the offload path.
    `DefaultRenderersFactory` | `setEnableAudioTrackPlaybackParams​(boolean enableAudioTrackPlaybackParams)` | Sets whether to enable setting playback speed using `AudioTrack.setPlaybackParams(PlaybackParams)`, which is supported from API level 23, rather than using application-level audio speed adjustment.
    `DefaultRenderersFactory` | `setEnableDecoderFallback​(boolean enableDecoderFallback)` | Sets whether to enable fallback to lower-priority decoders if decoder initialization fails.
    `DefaultRenderersFactory` | `setExtensionRendererMode​(@com.google.android.exoplayer2.DefaultRenderersFactory.ExtensionRendererMode int extensionRendererMode)` | Sets the extension renderer mode, which determines if and how available extension renderers are used.
    `DefaultRenderersFactory` | `setMediaCodecSelector​(MediaCodecSelector mediaCodecSelector)` | Sets a `MediaCodecSelector` for use by `MediaCodec` based renderers.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### DEFAULT_ALLOWED_VIDEO_JOINING_TIME_MS

          public static final long DEFAULT_ALLOWED_VIDEO_JOINING_TIME_MS

      The default maximum duration for which a video renderer can attempt to seamlessly join an ongoing playback.
      See Also:
        Constant Field Values

    - #### EXTENSION_RENDERER_MODE_OFF

          public static final int EXTENSION_RENDERER_MODE_OFF

      Do not allow use of extension renderers.
      See Also:
        Constant Field Values

    - #### EXTENSION_RENDERER_MODE_ON

          public static final int EXTENSION_RENDERER_MODE_ON

      Allow use of extension renderers. Extension renderers are indexed after core renderers of the same type. A `TrackSelector` that prefers the first suitable renderer will therefore prefer to use a core renderer to an extension renderer in the case that both are able to play a given track.
      See Also:
        Constant Field Values

    - #### EXTENSION_RENDERER_MODE_PREFER

          public static final int EXTENSION_RENDERER_MODE_PREFER

      Allow use of extension renderers. Extension renderers are indexed before core renderers of the same type. A `TrackSelector` that prefers the first suitable renderer will therefore prefer to use an extension renderer to a core renderer in the case that both are able to play a given track.
      See Also:
        Constant Field Values

    - #### MAX_DROPPED_VIDEO_FRAME_COUNT_TO_NOTIFY

          public static final int MAX_DROPPED_VIDEO_FRAME_COUNT_TO_NOTIFY

      The maximum number of frames that can be dropped between invocations of `VideoRendererEventListener.onDroppedFrames(int, long)`.
      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### DefaultRenderersFactory

          public DefaultRenderersFactory​(Context context)

      Parameters:
        `context` - A `Context`.

  - ### Method Detail

    - #### setExtensionRendererMode

          @CanIgnoreReturnValue
          public DefaultRenderersFactory setExtensionRendererMode​(@com.google.android.exoplayer2.DefaultRenderersFactory.ExtensionRendererMode int extensionRendererMode)

      Sets the extension renderer mode, which determines if and how available extension renderers are used. Note that extensions must be included in the application build for them to be considered available.

      The default value is `EXTENSION_RENDERER_MODE_OFF`.

      Parameters:
        `extensionRendererMode` - The extension renderer mode.
      Returns:
        This factory, for convenience.

    - #### forceEnableMediaCodecAsynchronousQueueing

          @CanIgnoreReturnValue
          public DefaultRenderersFactory forceEnableMediaCodecAsynchronousQueueing()

      Enables `MediaCodecRenderer` instances to operate their `MediaCodec` in asynchronous mode and perform asynchronous queueing.

      This feature can be enabled only on devices with API versions >= 23. For devices with older API versions, this method is a no-op.

      Returns:
        This factory, for convenience.

    - #### forceDisableMediaCodecAsynchronousQueueing

          @CanIgnoreReturnValue
          public DefaultRenderersFactory forceDisableMediaCodecAsynchronousQueueing()

      Disables `MediaCodecRenderer` instances from operating their `MediaCodec` in asynchronous mode and perform asynchronous queueing. `MediaCodec` instances will be operated synchronous mode.
      Returns:
        This factory, for convenience.

    - #### experimentalSetSynchronizeCodecInteractionsWithQueueingEnabled

          @CanIgnoreReturnValue
          public DefaultRenderersFactory experimentalSetSynchronizeCodecInteractionsWithQueueingEnabled​(boolean enabled)

      Enable synchronizing codec interactions with asynchronous buffer queueing.

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

      Parameters:
        `enabled` - Whether codec interactions will be synchronized with asynchronous buffer queueing.
      Returns:
        This factory, for convenience.

    - #### setEnableDecoderFallback

          @CanIgnoreReturnValue
          public DefaultRenderersFactory setEnableDecoderFallback​(boolean enableDecoderFallback)

      Sets whether to enable fallback to lower-priority decoders if decoder initialization fails. This may result in using a decoder that is less efficient or slower than the primary decoder.
      Parameters:
        `enableDecoderFallback` - Whether to enable fallback to lower-priority decoders if decoder initialization fails.
      Returns:
        This factory, for convenience.

    - #### setMediaCodecSelector

          @CanIgnoreReturnValue
          public DefaultRenderersFactory setMediaCodecSelector​(MediaCodecSelector mediaCodecSelector)

      Sets a `MediaCodecSelector` for use by `MediaCodec` based renderers.

      The default value is `MediaCodecSelector.DEFAULT`.

      Parameters:
        `mediaCodecSelector` - The `MediaCodecSelector`.
      Returns:
        This factory, for convenience.

    - #### setEnableAudioFloatOutput

          @CanIgnoreReturnValue
          public DefaultRenderersFactory setEnableAudioFloatOutput​(boolean enableFloatOutput)

      Sets whether floating point audio should be output when possible.

      Enabling floating point output disables audio processing, but may allow for higher quality audio output.

      The default value is `false`.

      Parameters:
        `enableFloatOutput` - Whether to enable use of floating point audio output, if available.
      Returns:
        This factory, for convenience.

    - #### setEnableAudioOffload

          @CanIgnoreReturnValue
          public DefaultRenderersFactory setEnableAudioOffload​(boolean enableOffload)

      Sets whether audio should be played using the offload path.

      Audio offload disables ExoPlayer audio processing, but significantly reduces the energy consumption of the playback when `offload scheduling` is enabled.

      Most Android devices can only support one offload `AudioTrack` at a time and can invalidate it at any time. Thus an app can never be guaranteed that it will be able to play in offload.

      The default value is `false`.

      Parameters:
        `enableOffload` - Whether to enable use of audio offload for supported formats, if available.
      Returns:
        This factory, for convenience.

    - #### setEnableAudioTrackPlaybackParams

          @CanIgnoreReturnValue
          public DefaultRenderersFactory setEnableAudioTrackPlaybackParams​(boolean enableAudioTrackPlaybackParams)

      Sets whether to enable setting playback speed using `AudioTrack.setPlaybackParams(PlaybackParams)`, which is supported from API level 23, rather than using application-level audio speed adjustment. This setting has no effect on builds before API level 23 (application-level speed adjustment will be used in all cases).

      If enabled and supported, new playback speed settings will take effect more quickly because they are applied at the audio mixer, rather than at the point of writing data to the track.

      When using this mode, the maximum supported playback speed is limited by the size of the audio track's buffer. If the requested speed is not supported the player's event listener will be notified twice on setting playback speed, once with the requested speed, then again with the old playback speed reflecting the fact that the requested speed was not supported.

      Parameters:
        `enableAudioTrackPlaybackParams` - Whether to enable setting playback speed using `AudioTrack.setPlaybackParams(PlaybackParams)`.
      Returns:
        This factory, for convenience.

    - #### setAllowedVideoJoiningTimeMs

          @CanIgnoreReturnValue
          public DefaultRenderersFactory setAllowedVideoJoiningTimeMs​(long allowedVideoJoiningTimeMs)

      Sets the maximum duration for which video renderers can attempt to seamlessly join an ongoing playback.

      The default value is `DEFAULT_ALLOWED_VIDEO_JOINING_TIME_MS`.

      Parameters:
        `allowedVideoJoiningTimeMs` - The maximum duration for which video renderers can attempt to seamlessly join an ongoing playback, in milliseconds.
      Returns:
        This factory, for convenience.

    - #### createRenderers

          public Renderer[] createRenderers​(Handler eventHandler,
                                            VideoRendererEventListener videoRendererEventListener,
                                            AudioRendererEventListener audioRendererEventListener,
                                            TextOutput textRendererOutput,
                                            MetadataOutput metadataRendererOutput)

      Description copied from interface: `RenderersFactory`
      Builds the `Renderer` instances for an `ExoPlayer`.
      Specified by:
        `createRenderers` in interface `RenderersFactory`
      Parameters:
        `eventHandler` - A handler to use when invoking event listeners and outputs.
        `videoRendererEventListener` - An event listener for video renderers.
        `audioRendererEventListener` - An event listener for audio renderers.
        `textRendererOutput` - An output for text renderers.
        `metadataRendererOutput` - An output for metadata renderers.
      Returns:
        The `instances`.

    - #### buildVideoRenderers

          protected void buildVideoRenderers​(Context context,
                                             @com.google.android.exoplayer2.DefaultRenderersFactory.ExtensionRendererMode int extensionRendererMode,
                                             MediaCodecSelector mediaCodecSelector,
                                             boolean enableDecoderFallback,
                                             Handler eventHandler,
                                             VideoRendererEventListener eventListener,
                                             long allowedVideoJoiningTimeMs,
                                             ArrayList<Renderer> out)

      Builds video renderers for use by the player.
      Parameters:
        `context` - The `Context` associated with the player.
        `extensionRendererMode` - The extension renderer mode.
        `mediaCodecSelector` - A decoder selector.
        `enableDecoderFallback` - Whether to enable fallback to lower-priority decoders if decoder initialization fails. This may result in using a decoder that is slower/less efficient than the primary decoder.
        `eventHandler` - A handler associated with the main thread's looper.
        `eventListener` - An event listener.
        `allowedVideoJoiningTimeMs` - The maximum duration for which video renderers can attempt to seamlessly join an ongoing playback, in milliseconds.
        `out` - An array to which the built renderers should be appended.

    - #### buildAudioRenderers

          protected void buildAudioRenderers​(Context context,
                                             @com.google.android.exoplayer2.DefaultRenderersFactory.ExtensionRendererMode int extensionRendererMode,
                                             MediaCodecSelector mediaCodecSelector,
                                             boolean enableDecoderFallback,
                                             AudioSink audioSink,
                                             Handler eventHandler,
                                             AudioRendererEventListener eventListener,
                                             ArrayList<Renderer> out)

      Builds audio renderers for use by the player.
      Parameters:
        `context` - The `Context` associated with the player.
        `extensionRendererMode` - The extension renderer mode.
        `mediaCodecSelector` - A decoder selector.
        `enableDecoderFallback` - Whether to enable fallback to lower-priority decoders if decoder initialization fails. This may result in using a decoder that is slower/less efficient than the primary decoder.
        `audioSink` - A sink to which the renderers will output.
        `eventHandler` - A handler to use when invoking event listeners and outputs.
        `eventListener` - An event listener.
        `out` - An array to which the built renderers should be appended.

    - #### buildTextRenderers

          protected void buildTextRenderers​(Context context,
                                            TextOutput output,
                                            Looper outputLooper,
                                            @com.google.android.exoplayer2.DefaultRenderersFactory.ExtensionRendererMode int extensionRendererMode,
                                            ArrayList<Renderer> out)

      Builds text renderers for use by the player.
      Parameters:
        `context` - The `Context` associated with the player.
        `output` - An output for the renderers.
        `outputLooper` - The looper associated with the thread on which the output should be called.
        `extensionRendererMode` - The extension renderer mode.
        `out` - An array to which the built renderers should be appended.

    - #### buildMetadataRenderers

          protected void buildMetadataRenderers​(Context context,
                                                MetadataOutput output,
                                                Looper outputLooper,
                                                @com.google.android.exoplayer2.DefaultRenderersFactory.ExtensionRendererMode int extensionRendererMode,
                                                ArrayList<Renderer> out)

      Builds metadata renderers for use by the player.
      Parameters:
        `context` - The `Context` associated with the player.
        `output` - An output for the renderers.
        `outputLooper` - The looper associated with the thread on which the output should be called.
        `extensionRendererMode` - The extension renderer mode.
        `out` - An array to which the built renderers should be appended.

    - #### buildCameraMotionRenderers

          protected void buildCameraMotionRenderers​(Context context,
                                                    @com.google.android.exoplayer2.DefaultRenderersFactory.ExtensionRendererMode int extensionRendererMode,
                                                    ArrayList<Renderer> out)

      Builds camera motion renderers for use by the player.
      Parameters:
        `context` - The `Context` associated with the player.
        `extensionRendererMode` - The extension renderer mode.
        `out` - An array to which the built renderers should be appended.

    - #### buildMiscellaneousRenderers

          protected void buildMiscellaneousRenderers​(Context context,
                                                     Handler eventHandler,
                                                     @com.google.android.exoplayer2.DefaultRenderersFactory.ExtensionRendererMode int extensionRendererMode,
                                                     ArrayList<Renderer> out)

      Builds any miscellaneous renderers used by the player.
      Parameters:
        `context` - The `Context` associated with the player.
        `eventHandler` - A handler to use when invoking event listeners and outputs.
        `extensionRendererMode` - The extension renderer mode.
        `out` - An array to which the built renderers should be appended.

    - #### buildAudioSink

          @Nullable
          protected AudioSink buildAudioSink​(Context context,
                                             boolean enableFloatOutput,
                                             boolean enableAudioTrackPlaybackParams,
                                             boolean enableOffload)

      Builds an `AudioSink` to which the audio renderers will output.
      Parameters:
        `context` - The `Context` associated with the player.
        `enableFloatOutput` - Whether to enable use of floating point audio output, if available.
        `enableAudioTrackPlaybackParams` - Whether to enable setting playback speed using `AudioTrack.setPlaybackParams(PlaybackParams)`, if supported.
        `enableOffload` - Whether to enable use of audio offload for supported formats, if available.
      Returns:
        The `AudioSink` to which the audio renderers will output. May be `null` if no audio renderers are required. If `null` is returned then `buildAudioRenderers(android.content.Context, @com.google.android.exoplayer2.DefaultRenderersFactory.ExtensionRendererMode int, com.google.android.exoplayer2.mediacodec.MediaCodecSelector, boolean, com.google.android.exoplayer2.audio.AudioSink, android.os.Handler, com.google.android.exoplayer2.audio.AudioRendererEventListener, java.util.ArrayList<com.google.android.exoplayer2.Renderer>)` will not be called.

    - #### getCodecAdapterFactory

          protected MediaCodecAdapter.Factory getCodecAdapterFactory()

      Returns the `MediaCodecAdapter.Factory` that will be used when creating `MediaCodecRenderer` instances.