ForwardingPlayer


@UnstableApi
public class ForwardingPlayer implements Player


A Player that forwards method calls to another Player. Applications can use this class to suppress or modify specific operations, by overriding the respective methods.

Subclasses must ensure they maintain consistency with the Player interface, including interactions with Player.Listener, which can be quite fiddly. For example, if removing an available Player.Command and disabling the corresponding method, subclasses need to:

Many customization use-cases are instead better served by ForwardingSimpleBasePlayer, which allows subclasses to more concisely modify the behavior of an operation, or disallow a Player.Command. In many cases ForwardingSimpleBasePlayer should be used in preference to ForwardingPlayer.

Summary

Public constructors

Creates a new instance that forwards all operations to player.

Public methods

void

Calls addListener on the delegate.

void

Calls addMediaItem on the delegate.

void
addMediaItem(int index, MediaItem mediaItem)

Calls addMediaItem on the delegate.

void

Calls addMediaItems on the delegate.

void
addMediaItems(int index, List<MediaItem> mediaItems)

Calls addMediaItems on the delegate.

boolean

Calls canAdvertiseSession on the delegate and returns the result.

void

Calls clearMediaItems on the delegate.

void

Calls clearVideoSurface on the delegate.

void

Calls clearVideoSurface on the delegate.

void

Calls clearVideoSurfaceHolder on the delegate.

void

Calls clearVideoSurfaceView on the delegate.

void

Calls clearVideoTextureView on the delegate.

void

This method is deprecated.

Use decreaseDeviceVolume instead.

void

Calls decreaseDeviceVolume on the delegate.

Looper

Calls getApplicationLooper on the delegate and returns the result.

AudioAttributes

Calls getAudioAttributes on the delegate and returns the result.

Player.Commands

Calls getAvailableCommands on the delegate and returns the result.

int

Calls getBufferedPercentage on the delegate and returns the result.

long

Calls getBufferedPosition on the delegate and returns the result.

long

Calls getContentBufferedPosition on the delegate and returns the result.

long

Calls getContentDuration on the delegate and returns the result.

long

Calls getContentPosition on the delegate and returns the result.

int

Calls getCurrentAdGroupIndex on the delegate and returns the result.

int

Calls getCurrentAdIndexInAdGroup on the delegate and returns the result.

CueGroup

Calls getCurrentCues on the delegate and returns the result.

long

Calls getCurrentLiveOffset on the delegate and returns the result.

@Nullable Object

Calls getCurrentManifest on the delegate and returns the result.

@Nullable MediaItem

Calls getCurrentMediaItem on the delegate and returns the result.

int

Calls getCurrentMediaItemIndex on the delegate and returns the result.

int

Calls getCurrentPeriodIndex on the delegate and returns the result.

long

Calls getCurrentPosition on the delegate and returns the result.

Timeline

Calls getCurrentTimeline on the delegate and returns the result.

Tracks

Calls getCurrentTracks on the delegate and returns the result.

int

This method is deprecated.

Use getCurrentMediaItemIndex instead.

DeviceInfo

Calls getDeviceInfo on the delegate and returns the result.

int

Calls getDeviceVolume on the delegate and returns the result.

long

Calls getDuration on the delegate and returns the result.

long

Calls getMaxSeekToPreviousPosition on the delegate and returns the result.

MediaItem
getMediaItemAt(int index)

Calls getMediaItemAt on the delegate and returns the result.

int

Calls getMediaItemCount on the delegate and returns the result.

MediaMetadata

Calls getMediaMetadata on the delegate and returns the result.

int

Calls getNextMediaItemIndex on the delegate and returns the result.

int

This method is deprecated.

Use getNextMediaItemIndex instead.

boolean

Calls getPlayWhenReady on the delegate and returns the result.

PlaybackParameters

Calls getPlaybackParameters on the delegate and returns the result.

int

Calls getPlaybackState on the delegate and returns the result.

int

Calls getPlaybackSuppressionReason on the delegate and returns the result.

@Nullable PlaybackException

Calls getPlayerError on the delegate and returns the result.

MediaMetadata

Calls getPlaylistMetadata on the delegate and returns the result.

int

Calls getPreviousMediaItemIndex on the delegate and returns the result.

int

This method is deprecated.

Use getPreviousMediaItemIndex instead.

int

Calls getRepeatMode on the delegate and returns the result.

long

Calls getSeekBackIncrement on the delegate and returns the result.

long

Calls getSeekForwardIncrement on the delegate and returns the result.

boolean

Calls getShuffleModeEnabled on the delegate and returns the result.

Size

Calls getSurfaceSize on the delegate and returns the result.

long

Calls getTotalBufferedDuration on the delegate and returns the result.

TrackSelectionParameters

Calls getTrackSelectionParameters on the delegate and returns the result.

VideoSize

Calls getVideoSize on the delegate and returns the result.

float

Calls getVolume on the delegate and returns the result.

Player

Returns the Player to which operations are forwarded.

boolean

This method is deprecated.

Use hasNextMediaItem instead.

boolean

Calls hasNextMediaItem on the delegate and returns the result.

boolean

This method is deprecated.

Use hasNextMediaItem instead.

boolean

Calls hasPreviousMediaItem on the delegate and returns the result.

void

This method is deprecated.

Use increaseDeviceVolume instead.

void

Calls increaseDeviceVolume on the delegate.

boolean

Calls isCommandAvailable on the delegate and returns the result.

boolean

Calls isCurrentMediaItemDynamic on the delegate and returns the result.

boolean

Calls isCurrentMediaItemLive on the delegate and returns the result.

boolean

Calls isCurrentMediaItemSeekable on the delegate and returns the result.

boolean

This method is deprecated.

Use isCurrentMediaItemDynamic instead.

boolean

This method is deprecated.

Use isCurrentMediaItemLive instead.

boolean

This method is deprecated.

Use isCurrentMediaItemSeekable instead.

boolean

Calls isDeviceMuted on the delegate and returns the result.

boolean

Calls isLoading on the delegate and returns the result.

boolean

Calls isPlaying on the delegate and returns the result.

boolean

Calls isPlayingAd on the delegate and returns the result.

void
moveMediaItem(int currentIndex, int newIndex)

Calls moveMediaItem on the delegate.

void
moveMediaItems(int fromIndex, int toIndex, int newIndex)

Calls moveMediaItems on the delegate.

void

This method is deprecated.

Use seekToNextMediaItem instead.

void

Calls pause on the delegate.

void

Calls play on the delegate.

void

Calls prepare on the delegate.

void

Calls release on the delegate.

void

Calls removeListener on the delegate.

void
removeMediaItem(int index)

Calls removeMediaItem on the delegate.

void
removeMediaItems(int fromIndex, int toIndex)

Calls removeMediaItems on the delegate.

void
replaceMediaItem(int index, MediaItem mediaItem)

Calls replaceMediaItem on the delegate.

void
replaceMediaItems(
    int fromIndex,
    int toIndex,
    List<MediaItem> mediaItems
)

Calls replaceMediaItems on the delegate.

void

Calls seekBack on the delegate.

void

Calls seekForward on the delegate.

void
seekTo(long positionMs)

Calls seekTo on the delegate.

void
seekTo(int mediaItemIndex, long positionMs)

Calls seekTo on the delegate.

void

Calls seekToDefaultPosition on the delegate.

void
seekToDefaultPosition(int mediaItemIndex)

Calls seekToDefaultPosition on the delegate.

void

Calls seekToNext on the delegate.

void

Calls seekToNextMediaItem on the delegate.

void

This method is deprecated.

Use seekToNextMediaItem instead.

void

Calls seekToPrevious on the delegate.

void

Calls seekToPreviousMediaItem on the delegate.

void

This method is deprecated.

Use seekToPreviousMediaItem instead.

void
setAudioAttributes(
    AudioAttributes audioAttributes,
    boolean handleAudioFocus
)

Calls setAudioAttributes on the delegate.

void
setDeviceMuted(boolean muted)

This method is deprecated.

Use setDeviceMuted instead.

void
setDeviceMuted(boolean muted, @C.VolumeFlags int flags)

Calls setDeviceMuted on the delegate.

void
setDeviceVolume(int volume)

This method is deprecated.

Use setDeviceVolume instead.

void
setDeviceVolume(int volume, @C.VolumeFlags int flags)

Calls setDeviceVolume on the delegate.

void

Calls setMediaItem on the delegate.

void
setMediaItem(MediaItem mediaItem, boolean resetPosition)

Calls setMediaItem on the delegate.

void
setMediaItem(MediaItem mediaItem, long startPositionMs)

Calls setMediaItem on the delegate.

void

Calls setMediaItems on the delegate.

void
setMediaItems(List<MediaItem> mediaItems, boolean resetPosition)

Calls setMediaItems ()} on the delegate.

void
setMediaItems(
    List<MediaItem> mediaItems,
    int startIndex,
    long startPositionMs
)

Calls setMediaItems on the delegate.

void
setPlayWhenReady(boolean playWhenReady)

Calls setPlayWhenReady on the delegate.

void

Calls setPlaybackParameters on the delegate.

void
setPlaybackSpeed(float speed)

Calls setPlaybackSpeed on the delegate.

void

Calls setPlaylistMetadata on the delegate.

void

Calls setRepeatMode on the delegate.

void
setShuffleModeEnabled(boolean shuffleModeEnabled)

Calls setShuffleModeEnabled on the delegate.

void

Calls setTrackSelectionParameters on the delegate.

void

Calls setVideoSurface on the delegate.

void

Calls setVideoSurfaceHolder on the delegate.

void

Calls setVideoSurfaceView on the delegate.

void

Calls setVideoTextureView on the delegate.

void
setVolume(float volume)

Calls setVolume on the delegate.

void

Calls stop on the delegate.

Inherited Constants

From androidx.media3.common.Player
static final int

This field is deprecated.

Use COMMAND_ADJUST_DEVICE_VOLUME_WITH_FLAGS instead.

static final int

Command to increase and decrease the device volume and mute it with volume flags.

static final int

Command to change the media items in the playlist.

static final int

Command to get the player current AudioAttributes.

static final int

Command to get information about the currently playing MediaItem.

static final int

Command to get the device volume and whether it is muted.

static final int

This field is deprecated.

Use COMMAND_GET_METADATA instead.

static final int

Command to get metadata related to the playlist and current MediaItem.

static final int

Command to get the text that should currently be displayed by the player.

static final int

Command to get the information about the current timeline.

static final int

Command to get details of the current track selection.

static final int

Command to get the player volume.

static final int

Represents an invalid Command.

static final int

Command to start, pause or resume playback.

static final int

Command to prepare the player.

static final int

Command to release the player.

static final int

Command to seek back by a fixed increment inside the current MediaItem.

static final int

Command to seek forward by a fixed increment inside the current MediaItem.

static final int

Command to seek anywhere inside the current MediaItem.

static final int

This field is deprecated.

Use COMMAND_SEEK_IN_CURRENT_MEDIA_ITEM instead.

static final int

Command to seek to the default position of the current MediaItem.

static final int

Command to seek anywhere in any MediaItem.

static final int

Command to seek to a later position in the current MediaItem or the default position of the next MediaItem.

static final int

Command to seek to the default position of the next MediaItem.

static final int

This field is deprecated.

Use COMMAND_SEEK_TO_NEXT_MEDIA_ITEM instead.

static final int

Command to seek to an earlier position in the current MediaItem or the default position of the previous MediaItem.

static final int

Command to seek to the default position of the previous MediaItem.

static final int

This field is deprecated.

Use COMMAND_SEEK_TO_PREVIOUS_MEDIA_ITEM instead.

static final int

This field is deprecated.

Use COMMAND_SEEK_TO_MEDIA_ITEM instead.

static final int

Command to set the player's audio attributes.

static final int

This field is deprecated.

Use COMMAND_SET_DEVICE_VOLUME_WITH_FLAGS instead.

static final int

Command to set the device volume with volume flags.

static final int

Command to set a MediaItem.

static final int

This field is deprecated.

Use COMMAND_SET_PLAYLIST_METADATA instead.

static final int

Command to set the playlist metadata.

static final int

Command to set the repeat mode.

static final int

Command to enable shuffling.

static final int

Command to set the playback speed and pitch.

static final int

Command to set the player's track selection parameters.

static final int

Command to set and clear the surface on which to render the video.

static final int

Command to set the player volume.

static final int

Command to stop playback.

static final int

Automatic playback transition from one period in the timeline to the next.

static final int

Discontinuity introduced internally (e.g. by the source).

static final int

Discontinuity caused by the removal of the current period from the Timeline.

static final int

Seek within the current period or to another period.

static final int

Seek adjustment due to being unable to seek to the requested position or because the seek was permitted to be inexact.

static final int

Discontinuity introduced by a skipped silence.

static final int

Discontinuity introduced by a skipped period (for instance a skipped ad).

static final int

getAudioAttributes changed.

static final int

The audio session id was set.

static final int

isCommandAvailable changed for at least one Command.

static final int

getCurrentCues changed.

static final int

getDeviceInfo changed.

static final int

getDeviceVolume changed.

static final int

isLoading ()} changed.

static final int

isPlaying changed.

static final int

getMaxSeekToPreviousPosition changed.

static final int

getCurrentMediaItem changed or the player started repeating the current item.

static final int

getMediaMetadata changed.

static final int

Metadata associated with the current playback time changed.

static final int

getPlaybackParameters changed.

static final int

getPlaybackState changed.

static final int

getPlaybackSuppressionReason changed.

static final int

getPlayerError changed.

static final int

getPlaylistMetadata changed.

static final int

getPlayWhenReady changed.

static final int

A position discontinuity occurred.

static final int

A frame is rendered for the first time since setting the surface, or since the renderer was reset, or since the stream being rendered was changed.

static final int

getRepeatMode changed.

static final int

getSeekBackIncrement changed.

static final int

getSeekForwardIncrement changed.

static final int

getShuffleModeEnabled changed.

static final int

Skipping silences in the audio stream is enabled or disabled.

static final int

The size of the surface onto which the video is being rendered changed.

static final int

getCurrentTimeline changed.

static final int

getCurrentTracks changed.

static final int

getTrackSelectionParameters changed.

static final int

getVideoSize changed.

static final int

getVolume changed.

static final int

Playback has automatically transitioned to the next media item.

static final int

The current media item has changed because of a change in the playlist.

static final int

The media item has been repeated.

static final int

A seek to another media item has occurred.

static final int

Playback is not suppressed.

static final int

Playback is suppressed due to transient audio focus loss.

static final int

Playback is suppressed due to attempt to play on an unsuitable audio output (e.g. attempt to play on built-in speaker on a Wear OS device).

static final int

This field is deprecated.

Use PLAYBACK_SUPPRESSION_REASON_UNSUITABLE_AUDIO_OUTPUT instead.

static final int

Playback has been paused to avoid becoming noisy.

static final int

Playback has been paused because of a loss of audio focus.

static final int

Playback has been paused at the end of a media item.

static final int

Playback has been started or paused because of a remote change.

static final int

Playback has been paused because playback has been suppressed too long.

static final int

Playback has been started or paused by a call to setPlayWhenReady.

static final int

Repeats the entire timeline infinitely.

static final int

Normal playback without repetition.

static final int

Repeats the currently playing MediaItem infinitely during ongoing playback.

static final int

The player is not able to immediately play the media, but is doing work toward being able to do so.

static final int

The player has finished playing the media.

static final int

The player is idle, meaning it holds only limited resources.

static final int

The player is able to immediately play from its current position.

static final int

Timeline changed as a result of a change of the playlist items or the order of the items.

static final int

Timeline changed as a result of a source update (e.g. result of a dynamic update by the played media).

Public constructors

ForwardingPlayer

public ForwardingPlayer(Player player)

Creates a new instance that forwards all operations to player.

Public methods

addListener

public void addListener(Player.Listener listener)

Calls addListener on the delegate.

Overrides of this method must not directly call delegate.addListener. If the override wants to pass the Player.Listener instance to the delegate Player, it must do so by calling super.addListener instead. This ensures the correct Player instance is passed to onEvents (i.e. this forwarding instance, and not the underlying delegate instance).

addMediaItem

public void addMediaItem(MediaItem mediaItem)

Calls addMediaItem on the delegate.

addMediaItem

public void addMediaItem(int index, MediaItem mediaItem)

Calls addMediaItem on the delegate.

addMediaItems

public void addMediaItems(List<MediaItem> mediaItems)

Calls addMediaItems on the delegate.

addMediaItems

public void addMediaItems(int index, List<MediaItem> mediaItems)

Calls addMediaItems on the delegate.

canAdvertiseSession

public boolean canAdvertiseSession()

Calls canAdvertiseSession on the delegate and returns the result.

clearMediaItems

public void clearMediaItems()

Calls clearMediaItems on the delegate.

clearVideoSurface

public void clearVideoSurface()

Calls clearVideoSurface on the delegate.

clearVideoSurface

public void clearVideoSurface(@Nullable Surface surface)

Calls clearVideoSurface on the delegate.

clearVideoSurfaceHolder

public void clearVideoSurfaceHolder(@Nullable SurfaceHolder surfaceHolder)

Calls clearVideoSurfaceHolder on the delegate.