CompositionPlayer
@ExperimentalApi
public final class CompositionPlayer extends SimpleBasePlayer
| java.lang.Object | |||
| ↳ | 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 |
|---|
public final class CompositionPlayer.BuilderA builder for |
Public methods |
|
|---|---|
void |
addAnalyticsListener(AnalyticsListener listener)Adds an |
void |
Forces the effect pipeline to redraw the effects immediately. |
Clock |
getClock()Returns the |
@Nullable Looper |
Returns the |
boolean |
Returns whether the player is optimized for scrubbing (many frequent seeks). |
void |
removeAnalyticsListener(AnalyticsListener listener)Removes an |
void |
setComposition(Composition composition)Sets the |
void |
setComposition(Sets the |
void |
setScrubbingModeEnabled(boolean scrubbingModeEnabled)Sets whether to optimize the player for scrubbing (many frequent seeks). |
void |
setVideoFrameMetadataListener(Sets the |
void |
setVideoSurface(Surface surface, Size videoOutputSize) |
Protected methods |
|
|---|---|
SimpleBasePlayer.State |
getState()Returns the current |
ListenableFuture<Object> |
handleClearVideoOutput(@Nullable Object videoOutput)Handles calls to clear the video output. |
ListenableFuture<Object> |
Handles calls to |
ListenableFuture<Object> |
Handles calls to |
ListenableFuture<Object> |
handleSeek(Handles calls to seekTo and other seek operations (for example, |
ListenableFuture<Object> |
handleSetAudioAttributes(Handles calls to set the audio attributes. |
ListenableFuture<Object> |
handleSetPlayWhenReady(boolean playWhenReady)Handles calls to |
ListenableFuture<Object> |
handleSetRepeatMode(@Player.RepeatMode int repeatMode)Handles calls to |
ListenableFuture<Object> |
handleSetVideoOutput(Object videoOutput)Handles calls to set the video output. |
ListenableFuture<Object> |
handleSetVolume(Handles calls to |
ListenableFuture<Object> |
Handles calls to |
Inherited Constants |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Inherited fields |
||
|---|---|---|
|
||
|
Inherited methods |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Public methods
addAnalyticsListener
public void addAnalyticsListener(AnalyticsListener listener)
Adds an AnalyticsListener to receive analytics events.
This method can be called from any thread.
| Parameters | |
|---|---|
AnalyticsListener listener |
The listener to be added. |
experimentalRedrawLastFrame
public void experimentalRedrawLastFrame()
Forces the effect pipeline to redraw the effects immediately.
The player must be built with replayable cache support.
getClock
public Clock getClock()
Returns the Clock used for playback.
This method can be called from any thread.
getPlaybackLooper
public @Nullable Looper getPlaybackLooper()
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
public boolean isScrubbingModeEnabled()
Returns whether the player is optimized for scrubbing (many frequent seeks).
removeAnalyticsListener
public void removeAnalyticsListener(AnalyticsListener listener)
Removes an AnalyticsListener.
| Parameters | |
|---|---|
AnalyticsListener listener |
The listener to be removed. |
setComposition
public void setComposition(Composition composition)
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
public void setComposition(
Composition composition,
@IntRange(from = 0) long startPositionMs
)
Sets the Composition to play.
| Parameters | |
|---|---|
Composition composition |
The |
@IntRange(from = 0) long startPositionMs |
The position at which playback should start, in milliseconds. |
setScrubbingModeEnabled
public void setScrubbingModeEnabled(boolean scrubbingModeEnabled)
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 | |
|---|---|
boolean scrubbingModeEnabled |
Whether scrubbing mode should be enabled. |
setVideoFrameMetadataListener
public void setVideoFrameMetadataListener(
VideoFrameMetadataListener videoFrameMetadataListener
)
Sets the VideoFrameMetadataListener.
Protected methods
getState
protected SimpleBasePlayer.State getState()
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 ListenableFuture<Object> handleClearVideoOutput(@Nullable Object videoOutput)
Handles calls to clear the video output.
Will only be called if COMMAND_SET_VIDEO_SURFACE is available.
| Parameters | |
|---|---|
@Nullable Object videoOutput |
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<Object> |
A |
handlePrepare
protected ListenableFuture<Object> handlePrepare()
Handles calls to prepare.
Will only be called if COMMAND_PREPARE is available.
| Returns | |
|---|---|
ListenableFuture<Object> |
A |
handleRelease
protected ListenableFuture<Object> handleRelease()
Handles calls to release.
Will only be called if COMMAND_RELEASE is available.
| Returns | |
|---|---|
ListenableFuture<Object> |
A |
handleSeek
protected ListenableFuture<Object> handleSeek(
int mediaItemIndex,
long positionMs,
@Player.Command int seekCommand
)
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 | |
|---|---|
int mediaItemIndex |
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 |
long positionMs |
The position in milliseconds to start playback from, or |
@Player.Command int seekCommand |
The |
| Returns | |
|---|---|
ListenableFuture<Object> |
A |
handleSetAudioAttributes
protected ListenableFuture<Object> handleSetAudioAttributes(
AudioAttributes audioAttributes,
boolean handleAudioFocus
)
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. |
boolean handleAudioFocus |
True if the player should handle audio focus, false otherwise. |
| Returns | |
|---|---|
ListenableFuture<Object> |
A |
handleSetPlayWhenReady
protected ListenableFuture<Object> handleSetPlayWhenReady(boolean playWhenReady)
Handles calls to setPlayWhenReady, play and pause.
Will only be called if COMMAND_PLAY_PAUSE is available.
| Parameters | |
|---|---|
boolean playWhenReady |
The requested |
| Returns | |
|---|---|
ListenableFuture<Object> |
A |
handleSetRepeatMode
protected ListenableFuture<Object> handleSetRepeatMode(@Player.RepeatMode int repeatMode)
Handles calls to setRepeatMode.
Will only be called if COMMAND_SET_REPEAT_MODE is available.
| Parameters | |
|---|---|
@Player.RepeatMode int repeatMode |
The requested |
| Returns | |
|---|---|
ListenableFuture<Object> |
A |
handleSetVideoOutput
protected ListenableFuture<Object> handleSetVideoOutput(Object videoOutput)
Handles calls to set the video output.
Will only be called if COMMAND_SET_VIDEO_SURFACE is available.
| Parameters | |
|---|---|
Object videoOutput |
The requested video output. This is either a |
| Returns | |
|---|---|
ListenableFuture<Object> |
A |
handleSetVolume
protected ListenableFuture<Object> handleSetVolume(
float volume,
@C.VolumeOperationType int volumeOperationType
)
Handles calls to setVolume.
Will only be called if COMMAND_SET_VOLUME is available.
| Parameters | |
|---|---|
float volume |
The requested audio volume, with 0 being silence and 1 being unity gain (signal unchanged). |
@C.VolumeOperationType int volumeOperationType |
The |
| Returns | |
|---|---|
ListenableFuture<Object> |
A |
handleStop
protected ListenableFuture<Object> handleStop()
Handles calls to stop.
Will only be called if COMMAND_STOP is available.
| Returns | |
|---|---|
ListenableFuture<Object> |
A |