CompositionPlayer.Builder


public final class CompositionPlayer.Builder


A builder for CompositionPlayer instances.

Summary

Public constructors

Builder(Context context)

Creates an instance

Public methods

CompositionPlayer

Builds the CompositionPlayer instance.

CompositionPlayer.Builder

Sets whether to enable replayable cache.

CompositionPlayer.Builder
@CanIgnoreReturnValue
experimentalSetLateThresholdToDropInputUs(
    long lateThresholdToDropInputUs
)

Sets the late threshold for decoded frames, in microseconds, after which frames may be dropped before applying effects.

CompositionPlayer.Builder
@CanIgnoreReturnValue
setAudioAttributes(
    AudioAttributes audioAttributes,
    boolean handleAudioFocus
)

Sets AudioAttributes that will be used by the player and whether to handle audio focus.

CompositionPlayer.Builder

Sets the AudioMixer.Factory to be used when audio mixing is needed.

CompositionPlayer.Builder

Sets the AudioSink that will be used to play out audio.

CompositionPlayer.Builder

Sets the Clock that will be used by the player.

CompositionPlayer.Builder

Sets the GlObjectsProvider to be used by the effect processing pipeline.

CompositionPlayer.Builder

Sets the ExecutorService to execute GL commands from.

CompositionPlayer.Builder

Sets an ImageDecoder.Factory that will create the ImageDecoder instances to decode images.

CompositionPlayer.Builder

Sets the LoadControl that will be used by the player to control buffering of all media items in a Composition.

CompositionPlayer.Builder

Sets the Looper from which the player can be accessed and Listener callbacks are dispatched too.

CompositionPlayer.Builder

Sets the MediaSource.Factory that *creates* the MediaSource for MediaItems in a Composition.

CompositionPlayer.Builder

Sets the VideoGraph.Factory that will be used by the player.

Public constructors

Builder

public Builder(Context context)

Creates an instance

Parameters
Context context

The application context.

Public methods

build

public CompositionPlayer build()

Builds the CompositionPlayer instance. Must be called at most once.

If no Looper has been called with setLooper, then this method must be called within a Looper thread which is the thread that can access the player instance and where Listener callbacks are dispatched.

experimentalSetEnableReplayableCache

@CanIgnoreReturnValue
public CompositionPlayer.Builder experimentalSetEnableReplayableCache(boolean enableReplayableCache)

Sets whether to enable replayable cache.

By default, the replayable cache is not enabled. Enable it to achieve accurate effect update, at the cost of using more power and computing resources.

Parameters
boolean enableReplayableCache

Whether replayable cache is enabled.

Returns
CompositionPlayer.Builder

This builder, for convenience.

experimentalSetLateThresholdToDropInputUs

@CanIgnoreReturnValue
public CompositionPlayer.Builder experimentalSetLateThresholdToDropInputUs(
    long lateThresholdToDropInputUs
)

Sets the late threshold for decoded frames, in microseconds, after which frames may be dropped before applying effects.

The default value is LATE_US_TO_DROP_INPUT_FRAME.

Set this threshold to TIME_UNSET to disable frame dropping before effects are applied.

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

Parameters
long lateThresholdToDropInputUs

The threshold.

setAudioAttributes

@CanIgnoreReturnValue
public CompositionPlayer.Builder setAudioAttributes(
    AudioAttributes audioAttributes,
    boolean handleAudioFocus
)

Sets AudioAttributes that will be used by the player and whether to handle audio focus.

If audio focus should be handled, the usage must be USAGE_MEDIA or USAGE_GAME. Other usages will throw an IllegalArgumentException.

Parameters
AudioAttributes audioAttributes

AudioAttributes.

boolean handleAudioFocus

Whether the player should handle audio focus.

Returns
CompositionPlayer.Builder

This builder.

setAudioMixerFactory

@CanIgnoreReturnValue
public CompositionPlayer.Builder setAudioMixerFactory(AudioMixer.Factory audioMixerFactory)

Sets the AudioMixer.Factory to be used when audio mixing is needed.

The default value is a DefaultAudioMixer.Factory with default values.

Parameters
AudioMixer.Factory audioMixerFactory

A AudioMixer.Factory.

Returns
CompositionPlayer.Builder

This builder.

setAudioSink

@CanIgnoreReturnValue
public CompositionPlayer.Builder setAudioSink(AudioSink audioSink)

Sets the AudioSink that will be used to play out audio.

By default, a DefaultAudioSink with its default configuration is used.

Parameters
AudioSink audioSink

The AudioSink.

Returns
CompositionPlayer.Builder

This builder, for convenience.

setClock

@VisibleForTesting
@CanIgnoreReturnValue
public CompositionPlayer.Builder setClock(Clock clock)

Sets the Clock that will be used by the player.

By default, DEFAULT is used.

Parameters
Clock clock

The Clock.

Returns
CompositionPlayer.Builder

This builder, for convenience.

setGlObjectsProvider

@CanIgnoreReturnValue
public CompositionPlayer.Builder setGlObjectsProvider(GlObjectsProvider glObjectsProvider)

Sets the GlObjectsProvider to be used by the effect processing pipeline.

Setting a GlObjectsProvider is no-op if a VideoGraph.Factory is set. By default, a DefaultGlObjectsProvider is used.

Parameters
GlObjectsProvider glObjectsProvider

The GlObjectsProvider.

Returns
CompositionPlayer.Builder

This builder, for convenience.

setGlThreadExecutorService

@CanIgnoreReturnValue
public CompositionPlayer.Builder setGlThreadExecutorService(ExecutorService glExecutorService)

Sets the ExecutorService to execute GL commands from.

By default, a newSingleThreadScheduledExecutor, owned and shutdown by the effects pipeline is used.

If set, the ExecutorService must be shut down by the caller after CompositionPlayer has been released.

Parameters
ExecutorService glExecutorService

The ExecutorService.

Returns
CompositionPlayer.Builder

This builder, for convenience.

setImageDecoderFactory

@CanIgnoreReturnValue
public CompositionPlayer.Builder setImageDecoderFactory(ImageDecoder.Factory imageDecoderFactory)

Sets an ImageDecoder.Factory that will create the ImageDecoder instances to decode images.

By default, an instance of BitmapFactoryImageDecoder.Factory is used, with a max output size set to be consistent with Transformer.

Parameters
ImageDecoder.Factory imageDecoderFactory

The ImageDecoder.Factory.

Returns
CompositionPlayer.Builder

This builder, for convenience.

setLoadControl

@CanIgnoreReturnValue
public CompositionPlayer.Builder setLoadControl(LoadControl loadControl)

Sets the LoadControl that will be used by the player to control buffering of all media items in a Composition.

By default, a DefaultLoadControl is used.

Parameters
LoadControl loadControl

A LoadControl.

Returns
CompositionPlayer.Builder

This builder, for convenience.

setLooper

@CanIgnoreReturnValue
public CompositionPlayer.Builder setLooper(Looper looper)

Sets the Looper from which the player can be accessed and Listener callbacks are dispatched too.

By default, the builder uses the looper of the thread that calls build.

Parameters
Looper looper

The Looper.

Returns
CompositionPlayer.Builder

This builder, for convenience.

setMediaSourceFactory

@CanIgnoreReturnValue
public CompositionPlayer.Builder setMediaSourceFactory(MediaSource.Factory mediaSourceFactory)

Sets the MediaSource.Factory that *creates* the MediaSource for MediaItems in a Composition.

To use an external image loader, one could create a DefaultMediaSourceFactory, set the external image loader, and pass in the DefaultMediaSourceFactory here.

Parameters
MediaSource.Factory mediaSourceFactory

The MediaSource.Factory

Returns
CompositionPlayer.Builder

This builder, for convenience.

setVideoGraphFactory

@CanIgnoreReturnValue
public CompositionPlayer.Builder setVideoGraphFactory(VideoGraph.Factory videoGraphFactory)

Sets the VideoGraph.Factory that will be used by the player.

By default, a SingleInputVideoGraph.Factory is used.

Parameters
VideoGraph.Factory videoGraphFactory

The VideoGraph.Factory.

Returns
CompositionPlayer.Builder

This builder, for convenience.