CompositionPlayer.Builder


class CompositionPlayer.Builder


A builder for CompositionPlayer instances.

Summary

Public constructors

Builder(context: Context!)

Creates an instance

Public functions

CompositionPlayer!

Builds the CompositionPlayer instance.

CompositionPlayer.Builder!

Sets whether to enable replayable cache.

CompositionPlayer.Builder!

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

CompositionPlayer.Builder!
@CanIgnoreReturnValue
setAudioAttributes(
    audioAttributes: AudioAttributes!,
    handleAudioFocus: Boolean
)

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

Builder(context: Context!)

Creates an instance

Parameters
context: Context!

The application context.

Public functions

build

fun build(): CompositionPlayer!

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
fun experimentalSetEnableReplayableCache(enableReplayableCache: Boolean): CompositionPlayer.Builder!

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
enableReplayableCache: Boolean

Whether replayable cache is enabled.

Returns
CompositionPlayer.Builder!

This builder, for convenience.

experimentalSetLateThresholdToDropInputUs

@CanIgnoreReturnValue
fun experimentalSetLateThresholdToDropInputUs(
    lateThresholdToDropInputUs: Long
): CompositionPlayer.Builder!

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
lateThresholdToDropInputUs: Long

The threshold.

setAudioAttributes

@CanIgnoreReturnValue
fun setAudioAttributes(
    audioAttributes: AudioAttributes!,
    handleAudioFocus: Boolean
): CompositionPlayer.Builder!

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.

handleAudioFocus: Boolean

Whether the player should handle audio focus.

Returns
CompositionPlayer.Builder!

This builder.

setAudioMixerFactory

@CanIgnoreReturnValue
fun setAudioMixerFactory(audioMixerFactory: AudioMixer.Factory!): CompositionPlayer.Builder!

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

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

Parameters
audioMixerFactory: AudioMixer.Factory!

A AudioMixer.Factory.

Returns
CompositionPlayer.Builder!

This builder.

setAudioSink

@CanIgnoreReturnValue
fun setAudioSink(audioSink: AudioSink!): CompositionPlayer.Builder!

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
fun setClock(clock: Clock!): CompositionPlayer.Builder!

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
fun setGlObjectsProvider(glObjectsProvider: GlObjectsProvider!): CompositionPlayer.Builder!

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
fun setGlThreadExecutorService(glExecutorService: ExecutorService!): CompositionPlayer.Builder!

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
glExecutorService: ExecutorService!

The ExecutorService.

Returns
CompositionPlayer.Builder!

This builder, for convenience.

setImageDecoderFactory

@CanIgnoreReturnValue
fun setImageDecoderFactory(imageDecoderFactory: ImageDecoder.Factory!): CompositionPlayer.Builder!

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
imageDecoderFactory: ImageDecoder.Factory!

The ImageDecoder.Factory.

Returns
CompositionPlayer.Builder!

This builder, for convenience.

setLoadControl

@CanIgnoreReturnValue
fun setLoadControl(loadControl: LoadControl!): CompositionPlayer.Builder!

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
fun setLooper(looper: Looper!): CompositionPlayer.Builder!

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
fun setMediaSourceFactory(mediaSourceFactory: MediaSource.Factory!): CompositionPlayer.Builder!

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
mediaSourceFactory: MediaSource.Factory!

The MediaSource.Factory

Returns
CompositionPlayer.Builder!

This builder, for convenience.

setVideoGraphFactory

@CanIgnoreReturnValue
fun setVideoGraphFactory(videoGraphFactory: VideoGraph.Factory!): CompositionPlayer.Builder!

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

By default, a SingleInputVideoGraph.Factory is used.

Parameters
videoGraphFactory: VideoGraph.Factory!

The VideoGraph.Factory.

Returns
CompositionPlayer.Builder!

This builder, for convenience.