DefaultRenderersFactory


@UnstableApi
public class DefaultRenderersFactory implements RenderersFactory


Default RenderersFactory implementation.

Summary

Nested types

@Documented
@Retention(value = RetentionPolicy.SOURCE)
@Target(value = TYPE_USE)
@IntDef(value = )
public annotation DefaultRenderersFactory.ExtensionRendererMode

Modes for using extension renderers.

Constants

static final long

The default maximum duration for which a video renderer can attempt to seamlessly join an ongoing playback.

static final int

Do not allow use of extension renderers.

static final int

Allow use of extension renderers.

static final int

Allow use of extension renderers.

static final int

The maximum number of frames that can be dropped between invocations of onDroppedFrames.

Public constructors

Public methods

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

Builds the Renderer instances for an ExoPlayer.

final DefaultRenderersFactory

Sets whether to enable CONFIGURE_FLAG_USE_CRYPTO_ASYNC on API 34 and above when operating the codec in asynchronous mode.

final DefaultRenderersFactory

Disables androidx.media3.exoplayer.mediacodec.MediaCodecRenderer instances from operating their MediaCodec in asynchronous mode and perform asynchronous queueing.

final DefaultRenderersFactory

Enables androidx.media3.exoplayer.mediacodec.MediaCodecRenderer instances to operate their MediaCodec in asynchronous mode and perform asynchronous queueing.

final DefaultRenderersFactory
@CanIgnoreReturnValue
setAllowedVideoJoiningTimeMs(long allowedVideoJoiningTimeMs)

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

final DefaultRenderersFactory

Sets whether floating point audio should be output when possible.

final DefaultRenderersFactory
@CanIgnoreReturnValue
setEnableAudioTrackPlaybackParams(
    boolean enableAudioTrackPlaybackParams
)

Sets whether to enable setting playback speed using setPlaybackParams, which is supported from API level 23, rather than using application-level audio speed adjustment.

final DefaultRenderersFactory
@CanIgnoreReturnValue
setEnableDecoderFallback(boolean enableDecoderFallback)

Sets whether to enable fallback to lower-priority decoders if decoder initialization fails.

final DefaultRenderersFactory

Sets the extension renderer mode, which determines if and how available extension renderers are used.

final DefaultRenderersFactory

Sets a MediaCodecSelector for use by MediaCodec based renderers.

Protected methods

void
buildAudioRenderers(
    Context context,
    @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.

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

Builds an AudioSink to which the audio renderers will output.

void
buildCameraMotionRenderers(
    Context context,
    @DefaultRenderersFactory.ExtensionRendererMode int extensionRendererMode,
    ArrayList<Renderer> out
)

Builds camera motion renderers for use by the player.

void

Builds image renderers for use by the player.

void
buildMetadataRenderers(
    Context context,
    MetadataOutput output,
    Looper outputLooper,
    @DefaultRenderersFactory.ExtensionRendererMode int extensionRendererMode,
    ArrayList<Renderer> out
)

Builds metadata renderers for use by the player.

void
buildMiscellaneousRenderers(
    Context context,
    Handler eventHandler,
    @DefaultRenderersFactory.ExtensionRendererMode int extensionRendererMode,
    ArrayList<Renderer> out
)

Builds any miscellaneous renderers used by the player.

void
buildTextRenderers(
    Context context,
    TextOutput output,
    Looper outputLooper,
    @DefaultRenderersFactory.ExtensionRendererMode int extensionRendererMode,
    ArrayList<Renderer> out
)

Builds text renderers for use by the player.

void
buildVideoRenderers(
    Context context,
    @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.

MediaCodecAdapter.Factory

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

ImageDecoder.Factory

Returns the ImageDecoder.Factory used to build the image renderer.

Constants

DEFAULT_ALLOWED_VIDEO_JOINING_TIME_MS

public static final long DEFAULT_ALLOWED_VIDEO_JOINING_TIME_MS = 5000

The default maximum duration for which a video renderer can attempt to seamlessly join an ongoing playback.

EXTENSION_RENDERER_MODE_OFF

public static final int EXTENSION_RENDERER_MODE_OFF = 0

Do not allow use of extension renderers.

EXTENSION_RENDERER_MODE_ON

public static final int EXTENSION_RENDERER_MODE_ON = 1

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.

EXTENSION_RENDERER_MODE_PREFER

public static final int EXTENSION_RENDERER_MODE_PREFER = 2

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.

MAX_DROPPED_VIDEO_FRAME_COUNT_TO_NOTIFY

public static final int MAX_DROPPED_VIDEO_FRAME_COUNT_TO_NOTIFY = 50

The maximum number of frames that can be dropped between invocations of onDroppedFrames.

Public constructors

DefaultRenderersFactory

public DefaultRenderersFactory(Context context)
Parameters
Context context

A Context.

Public methods

createRenderers

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

Builds the Renderer instances for an ExoPlayer.

Parameters
Handler eventHandler

A handler to use when invoking event listeners and outputs.

VideoRendererEventListener videoRendererEventListener

An event listener for video renderers.

AudioRendererEventListener audioRendererEventListener

An event listener for audio renderers.

TextOutput textRendererOutput

An output for text renderers.

MetadataOutput metadataRendererOutput

An output for metadata renderers.

Returns
Renderer[]

The instances.

experimentalSetMediaCodecAsyncCryptoFlagEnabled

@CanIgnoreReturnValue
public final DefaultRenderersFactory experimentalSetMediaCodecAsyncCryptoFlagEnabled(
    boolean enableAsyncCryptoFlag
)

Sets whether to enable CONFIGURE_FLAG_USE_CRYPTO_ASYNC on API 34 and above when operating the codec in asynchronous mode.

This method is experimental. Its default value may change, or it may be renamed or removed in a future release.

forceDisableMediaCodecAsynchronousQueueing

@CanIgnoreReturnValue
public final DefaultRenderersFactory forceDisableMediaCodecAsynchronousQueueing()

Disables androidx.media3.exoplayer.mediacodec.MediaCodecRenderer instances from operating their MediaCodec in asynchronous mode and perform asynchronous queueing. MediaCodec instances will be operated synchronous mode.

Returns
DefaultRenderersFactory

This factory, for convenience.

forceEnableMediaCodecAsynchronousQueueing

@CanIgnoreReturnValue
public final DefaultRenderersFactory forceEnableMediaCodecAsynchronousQueueing()

Enables androidx.media3.exoplayer.mediacodec.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
DefaultRenderersFactory

This factory, for convenience.

setAllowedVideoJoiningTimeMs

@CanIgnoreReturnValue
public final 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
long allowedVideoJoiningTimeMs

The maximum duration for which video renderers can attempt to seamlessly join an ongoing playback, in milliseconds.

Returns
DefaultRenderersFactory

This factory, for convenience.

setEnableAudioFloatOutput

@CanIgnoreReturnValue
public final 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
boolean enableFloatOutput

Whether to enable use of floating point audio output, if available.

Returns
DefaultRenderersFactory

This factory, for convenience.

setEnableAudioTrackPlaybackParams

@CanIgnoreReturnValue
public final DefaultRenderersFactory setEnableAudioTrackPlaybackParams(
    boolean enableAudioTrackPlaybackParams
)

Sets whether to enable setting playback speed using setPlaybackParams, 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
boolean enableAudioTrackPlaybackParams

Whether to enable setting playback speed using setPlaybackParams.

Returns
DefaultRenderersFactory

This factory, for convenience.

setEnableDecoderFallback

@CanIgnoreReturnValue
public final 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
boolean enableDecoderFallback

Whether to enable fallback to lower-priority decoders if decoder initialization fails.

Returns
DefaultRenderersFactory

This factory, for convenience.

setExtensionRendererMode

@CanIgnoreReturnValue
public final DefaultRenderersFactory setExtensionRendererMode(
    @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
@DefaultRenderersFactory.ExtensionRendererMode int extensionRendererMode

The extension renderer mode.

Returns
DefaultRenderersFactory

This factory, for convenience.

setMediaCodecSelector

@CanIgnoreReturnValue
public final DefaultRenderersFactory setMediaCodecSelector(MediaCodecSelector mediaCodecSelector)

Sets a MediaCodecSelector for use by MediaCodec based renderers.

The default value is DEFAULT.

Parameters
MediaCodecSelector mediaCodecSelector

The MediaCodecSelector.

Returns
DefaultRenderersFactory

This factory, for convenience.

Protected methods

buildAudioRenderers

protected void buildAudioRenderers(
    Context context,
    @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 context

The Context associated with the player.

@DefaultRenderersFactory.ExtensionRendererMode int extensionRendererMode

The extension renderer mode.

MediaCodecSelector mediaCodecSelector

A decoder selector.

boolean 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 audioSink

A sink to which the renderers will output.

Handler eventHandler

A handler to use when invoking event listeners and outputs.

AudioRendererEventListener eventListener

An event listener.

ArrayList<Renderer> out

An array to which the built renderers should be appended.

buildAudioSink

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

Builds an AudioSink to which the audio renderers will output.

Parameters
Context context

The Context associated with the player.

boolean enableFloatOutput

Whether to enable use of floating point audio output, if available.

boolean enableAudioTrackPlaybackParams

Whether to enable setting playback speed using setPlaybackParams, if supported.

Returns
@Nullable AudioSink

The AudioSink to which the audio renderers will output. May be null if no audio renderers are required. If null is returned then buildAudioRenderers will not be called.

buildCameraMotionRenderers

protected void buildCameraMotionRenderers(
    Context context,
    @DefaultRenderersFactory.ExtensionRendererMode int extensionRendererMode,
    ArrayList<Renderer> out
)

Builds camera motion renderers for use by the player.

Parameters
Context context

The Context associated with the player.

@DefaultRenderersFactory.ExtensionRendererMode int extensionRendererMode

The extension renderer mode.

ArrayList<Renderer> out

An array to which the built renderers should be appended.

buildImageRenderers

protected void buildImageRenderers(ArrayList<Renderer> out)

Builds image renderers for use by the player.

The ImageRenderer is built with ImageOutput set to null and set to ImageDecoder.Factory.DEFAULT by default.

Parameters
ArrayList<Renderer> out

An array to which the built renderers should be appended.

buildMetadataRenderers

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

Builds metadata renderers for use by the player.

Parameters
Context context

The Context associated with the player.

MetadataOutput output

An output for the renderers.

Looper outputLooper

The looper associated with the thread on which the output should be called.

@DefaultRenderersFactory.ExtensionRendererMode int extensionRendererMode

The extension renderer mode.

ArrayList<Renderer> out

An array to which the built renderers should be appended.

buildMiscellaneousRenderers

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

Builds any miscellaneous renderers used by the player.

Parameters
Context context

The Context associated with the player.

Handler eventHandler

A handler to use when invoking event listeners and outputs.

@DefaultRenderersFactory.ExtensionRendererMode int extensionRendererMode

The extension renderer mode.

ArrayList<Renderer> out

An array to which the built renderers should be appended.

buildTextRenderers

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

Builds text renderers for use by the player.

Parameters
Context context

The Context associated with the player.

TextOutput output

An output for the renderers.

Looper outputLooper

The looper associated with the thread on which the output should be called.

@DefaultRenderersFactory.ExtensionRendererMode int extensionRendererMode

The extension renderer mode.

ArrayList<Renderer> out

An array to which the built renderers should be appended.

buildVideoRenderers

protected void buildVideoRenderers(
    Context context,
    @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 context

The Context associated with the player.

@DefaultRenderersFactory.ExtensionRendererMode int extensionRendererMode

The extension renderer mode.

MediaCodecSelector mediaCodecSelector

A decoder selector.

boolean 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.

Handler eventHandler

A handler associated with the main thread's looper.

VideoRendererEventListener eventListener

An event listener.

long allowedVideoJoiningTimeMs

The maximum duration for which video renderers can attempt to seamlessly join an ongoing playback, in milliseconds.

ArrayList<Renderer> out

An array to which the built renderers should be appended.

getCodecAdapterFactory

protected MediaCodecAdapter.Factory getCodecAdapterFactory()

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

getImageDecoderFactory

protected ImageDecoder.Factory getImageDecoderFactory()

Returns the ImageDecoder.Factory used to build the image renderer.