CompositionPlayer
@ExperimentalApi
class CompositionPlayer : SimpleBasePlayer
| kotlin.Any | |||
| ↳ | androidx.media3.common.BasePlayer | ||
| ↳ | androidx.media3.common.SimpleBasePlayer | ||
| ↳ | androidx.media3.transformer.CompositionPlayer |
A Player implementation that plays compositions of media assets. The Composition specifies how the assets should be arranged, and the audio and video effects to apply to them.
CompositionPlayer instances must be accessed from a single application thread. For the vast majority of cases this should be the application's main thread. The thread on which a CompositionPlayer instance must be accessed can be explicitly specified by passing a Looper when creating the player. If no Looper is specified, then the Looper of the thread that the player is created on is used, or if that thread does not have a Looper, the Looper of the application's main thread is used. In all cases the Looper of the thread from which the player must be accessed can be queried using getApplicationLooper.
This player only supports setting the repeat mode as all of the Composition, or off.
Summary
Nested types |
|---|
|
A builder for |
Public functions |
|
|---|---|
Unit |
addAnalyticsListener(listener: AnalyticsListener!)Adds an |
Unit |
Forces the effect pipeline to redraw the effects immediately. |
Looper? |
Returns the |
Boolean |
Returns whether the player is optimized for scrubbing (many frequent seeks). |
Unit |
removeAnalyticsListener(listener: AnalyticsListener!)Removes an |
Unit |
setComposition(composition: Composition!)Sets the |
Unit |
setComposition(Sets the |
Unit |
setScrubbingModeEnabled(scrubbingModeEnabled: Boolean)Sets whether to optimize the player for scrubbing (many frequent seeks). |
Unit |
setVideoFrameMetadataListener(Sets the |
Unit |
setVideoSurface(surface: Surface!, videoOutputSize: Size!) |
Protected functions |
|
|---|---|
SimpleBasePlayer.State! |
getState()Returns the current |
ListenableFuture<Any!>! |
handleClearVideoOutput(videoOutput: Any?)Handles calls to clear the video output. |
ListenableFuture<Any!>! |
Handles calls to |
ListenableFuture<Any!>! |
Handles calls to |
ListenableFuture<Any!>! |
handleSeek(Handles calls to seekTo and other seek operations (for example, |
ListenableFuture<Any!>! |
handleSetAudioAttributes(Handles calls to set the audio attributes. |
ListenableFuture<Any!>! |
handleSetPlayWhenReady(playWhenReady: Boolean)Handles calls to |
ListenableFuture<Any!>! |
handleSetRepeatMode(@Player.RepeatMode repeatMode: Int)Handles calls to |
ListenableFuture<Any!>! |
handleSetVideoOutput(videoOutput: Any!)Handles calls to set the video output. |
ListenableFuture<Any!>! |
handleSetVolume(Handles calls to |
ListenableFuture<Any!>! |
Handles calls to |
Inherited Constants |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Inherited functions |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Inherited properties |
|---|
Public functions
addAnalyticsListener
fun addAnalyticsListener(listener: AnalyticsListener!): Unit
Adds an AnalyticsListener to receive analytics events.
This method can be called from any thread.
| Parameters | |
|---|---|
listener: AnalyticsListener! |
The listener to be added. |
experimentalRedrawLastFrame
fun experimentalRedrawLastFrame(): Unit
Forces the effect pipeline to redraw the effects immediately.
The player must be built with replayable cache support.
getPlaybackLooper
fun getPlaybackLooper(): Looper?
Returns the Looper associated with the playback thread or null if the internal player has not been prepared.
This method may be called from any thread.
isScrubbingModeEnabled
fun isScrubbingModeEnabled(): Boolean
Returns whether the player is optimized for scrubbing (many frequent seeks).
removeAnalyticsListener
fun removeAnalyticsListener(listener: AnalyticsListener!): Unit
Removes an AnalyticsListener.
| Parameters | |
|---|---|
listener: AnalyticsListener! |
The listener to be removed. |
setComposition
fun setComposition(composition: Composition!): Unit
Sets the Composition to play from the beginning.
Calling this method is equivalent to calling setComposition with a start position at zero.
| Parameters | |
|---|---|
composition: Composition! |
The |
setComposition
fun setComposition(
composition: Composition!,
startPositionMs: @IntRange(from = 0) Long
): Unit
Sets the Composition to play.
| Parameters | |
|---|---|
composition: Composition! |
The |
startPositionMs: @IntRange(from = 0) Long |
The position at which playback should start, in milliseconds. |
setScrubbingModeEnabled
fun setScrubbingModeEnabled(scrubbingModeEnabled: Boolean): Unit
Sets whether to optimize the player for scrubbing (many frequent seeks).
The player may consume more resources in this mode, so it should only be used for short periods of time in response to user interaction (e.g. dragging on a progress bar UI element).
During scrubbing mode playback is suppressed with PLAYBACK_SUPPRESSION_REASON_SCRUBBING.
| Parameters | |
|---|---|
scrubbingModeEnabled: Boolean |
Whether scrubbing mode should be enabled. |
setVideoFrameMetadataListener
fun setVideoFrameMetadataListener(
videoFrameMetadataListener: VideoFrameMetadataListener!
): Unit
Sets the VideoFrameMetadataListener.
Protected functions
getState
protected fun getState(): SimpleBasePlayer.State!
Returns the current State of the player.
The State should include all available commands indicating which player methods are allowed to be called.
Note that this method won't be called while asynchronous handling of player methods is in progress. This means that the implementation doesn't need to handle state changes caused by these asynchronous operations until they are done and can return the currently known state directly. The placeholder state used while these asynchronous operations are in progress can be customized by overriding getPlaceholderState if required.
handleClearVideoOutput
protected fun handleClearVideoOutput(videoOutput: Any?): ListenableFuture<Any!>!
Handles calls to clear the video output.
Will only be called if COMMAND_SET_VIDEO_SURFACE is available.
| Parameters | |
|---|---|
videoOutput: Any? |
The video output to clear. If null any current output should be cleared. If non-null, the output should only be cleared if it matches the provided argument. This is either a |
| Returns | |
|---|---|
ListenableFuture<Any!>! |
A |
handlePrepare
protected fun handlePrepare(): ListenableFuture<Any!>!
Handles calls to prepare.
Will only be called if COMMAND_PREPARE is available.
| Returns | |
|---|---|
ListenableFuture<Any!>! |
A |
handleRelease
protected fun handleRelease(): ListenableFuture<Any!>!
Handles calls to release.
Will only be called if COMMAND_RELEASE is available.
| Returns | |
|---|---|
ListenableFuture<Any!>! |
A |
handleSeek
protected fun handleSeek(
mediaItemIndex: Int,
positionMs: Long,
@Player.Command seekCommand: Int
): ListenableFuture<Any!>!
Handles calls to seekTo and other seek operations (for example, seekToNext).
Will only be called if the appropriate Player.Command, for example COMMAND_SEEK_TO_MEDIA_ITEM or COMMAND_SEEK_TO_NEXT, is available.
| Parameters | |
|---|---|
mediaItemIndex: Int |
The media item index to seek to. If the original seek operation did not directly specify an index, this is the most likely implied index based on the available player state. If the implied action is to do nothing, this will be |
positionMs: Long |
The position in milliseconds to start playback from, or |
@Player.Command seekCommand: Int |
The |
| Returns | |
|---|---|
ListenableFuture<Any!>! |
A |
handleSetAudioAttributes
protected fun handleSetAudioAttributes(
audioAttributes: AudioAttributes!,
handleAudioFocus: Boolean
): ListenableFuture<Any!>!
Handles calls to set the audio attributes.
Will only be called if COMMAND_SET_AUDIO_ATTRIBUTES is available.
| Parameters | |
|---|---|
audioAttributes: AudioAttributes! |
The attributes to use for audio playback. |
handleAudioFocus: Boolean |
True if the player should handle audio focus, false otherwise. |
| Returns | |
|---|---|
ListenableFuture<Any!>! |
A |
handleSetPlayWhenReady
protected fun handleSetPlayWhenReady(playWhenReady: Boolean): ListenableFuture<Any!>!
Handles calls to setPlayWhenReady, play and pause.
Will only be called if COMMAND_PLAY_PAUSE is available.
| Parameters | |
|---|---|
playWhenReady: Boolean |
The requested |
| Returns | |
|---|---|
ListenableFuture<Any!>! |
A |
handleSetRepeatMode
protected fun handleSetRepeatMode(@Player.RepeatMode repeatMode: Int): ListenableFuture<Any!>!
Handles calls to setRepeatMode.
Will only be called if COMMAND_SET_REPEAT_MODE is available.
| Parameters | |
|---|---|
@Player.RepeatMode repeatMode: Int |
The requested |
| Returns | |
|---|---|
ListenableFuture<Any!>! |
A |
handleSetVideoOutput
protected fun handleSetVideoOutput(videoOutput: Any!): ListenableFuture<Any!>!
Handles calls to set the video output.
Will only be called if COMMAND_SET_VIDEO_SURFACE is available.
| Parameters | |
|---|---|
videoOutput: Any! |
The requested video output. This is either a |
| Returns | |
|---|---|
ListenableFuture<Any!>! |
A |
handleSetVolume
protected fun handleSetVolume(
volume: Float,
@C.VolumeOperationType volumeOperationType: Int
): ListenableFuture<Any!>!
Handles calls to setVolume.
Will only be called if COMMAND_SET_VOLUME is available.
| Parameters | |
|---|---|
volume: Float |
The requested audio volume, with 0 being silence and 1 being unity gain (signal unchanged). |
@C.VolumeOperationType volumeOperationType: Int |
The |
| Returns | |
|---|---|
ListenableFuture<Any!>! |
A |
handleStop
protected fun handleStop(): ListenableFuture<Any!>!
Handles calls to stop.
Will only be called if COMMAND_STOP is available.
| Returns | |
|---|---|
ListenableFuture<Any!>! |
A |