ForwardingSimpleBasePlayer
@UnstableApi
public class ForwardingSimpleBasePlayer extends SimpleBasePlayer
| java.lang.Object | |||
| ↳ | androidx.media3.common.BasePlayer | ||
| ↳ | androidx.media3.common.SimpleBasePlayer | ||
| ↳ | androidx.media3.common.ForwardingSimpleBasePlayer |
A SimpleBasePlayer that forwards all calls to another Player instance.
The class can be used to selectively override getState or handle{Action} methods:
new ForwardingSimpleBasePlayer(player) { protected State getState() { State state = super.getState(); // Modify current state as required: return state.buildUpon().setAvailableCommands(filteredCommands).build(); } protected ListenableFuture<?> handleSetRepeatMode(int repeatMode) { // Modify actions by directly calling the underlying player as needed: getPlayer().setShuffleModeEnabled(true); // ..or forward to the default handling with modified parameters: return super.handleSetRepeatMode(Player.REPEAT_MODE_ALL); } }
SimpleBasePlayer for a more detailed description.
Summary
Public constructors |
|---|
ForwardingSimpleBasePlayer(Player player)Creates the forwarding player. |
Inherited Constants |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Inherited fields |
||
|---|---|---|
|
||
|
Inherited methods |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Public constructors
ForwardingSimpleBasePlayer
public ForwardingSimpleBasePlayer(Player player)
Creates the forwarding player.
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.
handleAddMediaItems
protected ListenableFuture<Object> handleAddMediaItems(int index, List<MediaItem> mediaItems)
Handles calls to addMediaItem and addMediaItems.
Will only be called if COMMAND_CHANGE_MEDIA_ITEMS is available.
| Parameters | |
|---|---|
int index |
The index at which to add the items. The index is in the range 0 <= |
List<MediaItem> mediaItems |
The media items to add. |
| Returns | |
|---|---|
ListenableFuture<Object> |
A |
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 |
handleDecreaseDeviceVolume
protected ListenableFuture<Object> handleDecreaseDeviceVolume(@C.VolumeFlags int flags)
Handles calls to decreaseDeviceVolume and decreaseDeviceVolume.
Will only be called if COMMAND_ADJUST_DEVICE_VOLUME or COMMAND_ADJUST_DEVICE_VOLUME_WITH_FLAGS is available.
| Parameters | |
|---|---|
@C.VolumeFlags int flags |
Either 0 or a bitwise combination of one or more |
| Returns | |
|---|---|
ListenableFuture<Object> |
A |
handleIncreaseDeviceVolume
protected ListenableFuture<Object> handleIncreaseDeviceVolume(@C.VolumeFlags int flags)
Handles calls to increaseDeviceVolume and increaseDeviceVolume.
Will only be called if COMMAND_ADJUST_DEVICE_VOLUME or COMMAND_ADJUST_DEVICE_VOLUME_WITH_FLAGS is available.
| Parameters | |
|---|---|
@C.VolumeFlags int flags |
Either 0 or a bitwise combination of one or more |
| Returns | |
|---|---|
ListenableFuture<Object> |
A |
handleMoveMediaItems
protected ListenableFuture<Object> handleMoveMediaItems(int fromIndex, int toIndex, int newIndex)
Handles calls to moveMediaItem and moveMediaItems.
Will only be called if COMMAND_CHANGE_MEDIA_ITEMS is available.
| Parameters | |
|---|---|
int fromIndex |
The start index of the items to move. The index is in the range 0 <= |
int toIndex |
The index of the first item not to be included in the move (exclusive). The index is in the range |
int newIndex |
The new index of the first moved item. The index is in the range |
| 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 |
handleRemoveMediaItems
protected ListenableFuture<Object> handleRemoveMediaItems(int fromIndex, int toIndex)
Handles calls to removeMediaItem and removeMediaItems.
Will only be called if COMMAND_CHANGE_MEDIA_ITEMS is available.
| Parameters | |
|---|---|
int fromIndex |
The index at which to start removing media items. The index is in the range 0 <= |
int toIndex |
The index of the first item to be kept (exclusive). The index is in the range |
| Returns | |
|---|---|
ListenableFuture<Object> |
A |
handleReplaceMediaItems
protected ListenableFuture<Object> handleReplaceMediaItems(
int fromIndex,
int toIndex,
List<MediaItem> mediaItems
)
Handles calls to replaceMediaItem and replaceMediaItems.
Will only be called if COMMAND_CHANGE_MEDIA_ITEMS is available.
| Parameters | |
|---|---|
int fromIndex |
The start index of the items to replace. The index is in the range 0 <= |
int toIndex |
The index of the first item not to be replaced (exclusive). The index is in the range |
List<MediaItem> mediaItems |
The media items to replace the specified range with. |
| 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 |
handleSetDeviceMuted
protected ListenableFuture<Object> handleSetDeviceMuted(boolean muted, @C.VolumeFlags int flags)
Handles calls to setDeviceMuted and setDeviceMuted.
Will only be called if COMMAND_ADJUST_DEVICE_VOLUME or COMMAND_ADJUST_DEVICE_VOLUME_WITH_FLAGS is available.
| Parameters | |
|---|---|
boolean muted |
Whether the device was requested to be muted. |
@C.VolumeFlags int flags |
Either 0 or a bitwise combination of one or more |
| Returns | |
|---|---|
ListenableFuture<Object> |
A |
handleSetDeviceVolume
protected ListenableFuture<Object> handleSetDeviceVolume(int deviceVolume, int flags)
Handles calls to setDeviceVolume and setDeviceVolume.
Will only be called if COMMAND_SET_DEVICE_VOLUME or COMMAND_SET_DEVICE_VOLUME_WITH_FLAGS is available.
| Parameters | |
|---|---|
int deviceVolume |
The requested device volume. |
int flags |
Either 0 or a bitwise combination of one or more |
| Returns | |
|---|---|
ListenableFuture<Object> |
A |
handleSetMediaItems
protected ListenableFuture<Object> handleSetMediaItems(
List<MediaItem> mediaItems,
int startIndex,
long startPositionMs
)
Handles calls to setMediaItem and setMediaItems.
Will only be called if COMMAND_SET_MEDIA_ITEM or COMMAND_CHANGE_MEDIA_ITEMS is available. If only COMMAND_SET_MEDIA_ITEM is available, the list of media items will always contain exactly one item.
| Parameters | |
|---|---|
List<MediaItem> mediaItems |
The media items to add. |
int startIndex |
The index at which to start playback from, or |
long startPositionMs |
The position in milliseconds to start playback from, or |
| 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 |
handleSetPlaybackParameters
protected ListenableFuture<Object> handleSetPlaybackParameters(PlaybackParameters playbackParameters)
Handles calls to setPlaybackParameters or setPlaybackSpeed.
Will only be called if COMMAND_SET_SPEED_AND_PITCH is available.
| Parameters | |
|---|---|
PlaybackParameters playbackParameters |
The requested |
| Returns | |
|---|---|
ListenableFuture<Object> |
A |
handleSetPlaylistMetadata
protected ListenableFuture<Object> handleSetPlaylistMetadata(MediaMetadata playlistMetadata)
Handles calls to setPlaylistMetadata.
Will only be called if COMMAND_SET_PLAYLIST_METADATA is available.
| Parameters | |
|---|---|
MediaMetadata playlistMetadata |
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 |
handleSetShuffleModeEnabled
protected ListenableFuture<Object> handleSetShuffleModeEnabled(boolean shuffleModeEnabled)
Handles calls to setShuffleModeEnabled.
Will only be called if COMMAND_SET_SHUFFLE_MODE is available.
| Parameters | |
|---|---|
boolean shuffleModeEnabled |
Whether shuffle mode was requested to be enabled. |
| Returns | |
|---|---|
ListenableFuture<Object> |
A |
handleSetTrackSelectionParameters
protected ListenableFuture<Object> handleSetTrackSelectionParameters(
TrackSelectionParameters trackSelectionParameters
)
Handles calls to setTrackSelectionParameters.
Will only be called if COMMAND_SET_TRACK_SELECTION_PARAMETERS is available.
| Parameters | |
|---|---|
TrackSelectionParameters trackSelectionParameters |
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 |
setPlayer
protected final void setPlayer(Player newPlayer)
Replaces the Player to forward with the given one.
Besides triggering listener calls due to any differences in the states of the old and the new player, changing the forwarded player using this method also triggers a position discontinuity with reason DISCONTINUITY_REASON_INTERNAL.
| Throws | |
|---|---|
java.lang.IllegalArgumentException |
If the provided player's |