@UnstableApi
public abstract class BasePlayer implements Player

Known direct subclasses
CastPlayer

Player implementation that communicates with a Cast receiver app.

SimpleBasePlayer

A base implementation for Player that reduces the number of methods to implement to a minimum.

SimpleExoPlayer

This class is deprecated.

Use ExoPlayer instead.

StubPlayer

An abstract Player implementation that throws UnsupportedOperationException from every method.

Known indirect subclasses
ForwardingSimpleBasePlayer

A SimpleBasePlayer that forwards all calls to another Player instance.

StubExoPlayer

An abstract ExoPlayer implementation that throws UnsupportedOperationException from every method.


Abstract base Player which implements common implementation independent methods.

Summary

Protected fields

final Timeline.Window

Protected constructors

Public methods

final void

Adds a media item to the end of the playlist.

final void
addMediaItem(int index, MediaItem mediaItem)

Adds a media item at the given index of the playlist.

final void

Adds a list of media items to the end of the playlist.

final boolean

Returns whether the player can be used to advertise a media session.

final void

Clears the playlist.

final int

Returns an estimate of the percentage in the current content or ad up to which data is buffered, or 0 if no estimate is available.

final long

If isPlayingAd returns true, returns the duration of the current content in milliseconds, or TIME_UNSET if the duration is not known.

final long

Returns the offset of the current playback position from the live edge in milliseconds, or TIME_UNSET if the current MediaItemisn't live or the offset is unknown.

final @Nullable Object

Returns the current manifest.

final @Nullable MediaItem

Returns the currently playing MediaItem.

final int

This method is deprecated.

Use getCurrentMediaItemIndex instead.

final MediaItem
getMediaItemAt(int index)

Returns the MediaItem at the given index.

final int

Returns the number of media items in the playlist.

final int

Returns the index of the MediaItem that will be played if seekToNextMediaItem is called, which may depend on the current repeat mode and whether shuffle mode is enabled.

final int

This method is deprecated.

Use getNextMediaItemIndex instead.

final int

Returns the index of the MediaItem that will be played if seekToPreviousMediaItem is called, which may depend on the current repeat mode and whether shuffle mode is enabled.

final int

This method is deprecated.

Use getPreviousMediaItemIndex instead.

final boolean

This method is deprecated.

Use hasNextMediaItem instead.

final boolean

Returns whether a next MediaItem exists, which may depend on the current repeat mode and whether shuffle mode is enabled.

final boolean

This method is deprecated.

Use hasNextMediaItem instead.

final boolean

Returns whether a previous media item exists, which may depend on the current repeat mode and whether shuffle mode is enabled.

final boolean

Returns whether the provided Command is available.

final boolean

Returns whether the current MediaItem is dynamic (may change when the Timeline is updated), or false if the Timeline is empty.

final boolean

Returns whether the current MediaItem is live, or false if the Timeline is empty.

final boolean

Returns whether the current MediaItem is seekable, or false if the is empty.

final boolean

This method is deprecated.

Use isCurrentMediaItemDynamic instead.

final boolean

This method is deprecated.

Use isCurrentMediaItemLive instead.

final boolean

This method is deprecated.

Use isCurrentMediaItemSeekable instead.

final boolean

Returns whether the player is playing, i.e. getCurrentPosition is advancing.

final void
moveMediaItem(int currentIndex, int newIndex)

Moves the media item at the current index to the new index.

final void

This method is deprecated.

Use seekToNextMediaItem instead.

final void

Pauses playback.

final void

Resumes playback as soon as getPlaybackState == STATE_READY.

final void
removeMediaItem(int index)

Removes the media item at the given index of the playlist.

final void
replaceMediaItem(int index, MediaItem mediaItem)

Replaces the media item at the given index of the playlist.

final void

Seeks back in the current MediaItem by getSeekBackIncrement milliseconds.

final void

Seeks forward in the current MediaItem by getSeekForwardIncrement milliseconds.

final void
seekTo(long positionMs)

Seeks to a position specified in milliseconds in the current MediaItem.

final void
seekTo(int mediaItemIndex, long positionMs)

Seeks to a position specified in milliseconds in the specified MediaItem.

abstract void
@VisibleForTesting(otherwise = 4)
seekTo(
    int mediaItemIndex,
    long positionMs,
    @Player.Command int seekCommand,
    boolean isRepeatingCurrentItem
)

Seeks to a position in the specified MediaItem.

final void

Seeks to the default position associated with the current MediaItem.

final void
seekToDefaultPosition(int mediaItemIndex)

Seeks to the default position associated with the specified MediaItem.

final void

Seeks to a later position in the current or next MediaItem (if available).

final void

Seeks to the default position of the next MediaItem, which may depend on the current repeat mode and whether shuffle mode is enabled.

final void

This method is deprecated.

Use seekToNextMediaItem instead.

final void

Seeks to an earlier position in the current or previous MediaItem (if available).

final void

Seeks to the default position of the previous MediaItem, which may depend on the current repeat mode and whether shuffle mode is enabled.

final void

This method is deprecated.

Use seekToPreviousMediaItem instead.

final void

Clears the playlist, adds the specified MediaItem and resets the position to the default position.

final void
setMediaItem(MediaItem mediaItem, boolean resetPosition)

Clears the playlist and adds the specified MediaItem.

final void
setMediaItem(MediaItem mediaItem, long startPositionMs)

Clears the playlist and adds the specified MediaItem.

final void

Clears the playlist, adds the specified media items and resets the position to the default position.

final void
setPlaybackSpeed(float speed)

Changes the rate at which playback occurs.

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).

Inherited methods

From androidx.media3.common.Player
abstract void

Registers a listener to receive all events from the player.

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

Adds a list of media items at the given index of the playlist.

abstract void

Clears any Surface, SurfaceHolder, SurfaceView or TextureView currently set on the player.

abstract void

Clears the Surface onto which video is being rendered if it matches the one passed.

abstract void

Clears the SurfaceHolder that holds the Surface onto which video is being rendered if it matches the one passed.

abstract void

Clears the SurfaceView onto which video is being rendered if it matches the one passed.

abstract void

Clears the TextureView onto which video is being rendered if it matches the one passed.

abstract void

This method is deprecated.

Use decreaseDeviceVolume instead.

abstract void

Decreases the volume of the device.

abstract Looper

Returns the Looper associated with the application thread that's used to access the player and on which player events are received.

abstract AudioAttributes

Returns the attributes for audio playback.

abstract Player.Commands

Returns the player's currently available Commands.

abstract long

Returns an estimate of the position in the current content or ad up to which data is buffered, in milliseconds.

abstract long

If isPlayingAd returns true, returns an estimate of the content position in the current content up to which data is buffered, in milliseconds.

abstract long

If isPlayingAd returns true, returns the content position that will be played once all ads in the ad group have finished playing, in milliseconds.

abstract int

If isPlayingAd returns true, returns the index of the ad group in the period currently being played.

abstract int

If isPlayingAd returns true, returns the index of the ad in its ad group.

abstract CueGroup

Returns the current CueGroup.

abstract int

Returns the index of the current MediaItem in the timeline, or the prospective index if the current timeline is empty.

abstract int

Returns the index of the period currently being played.

abstract long

Returns the playback position in the current content or ad, in milliseconds, or the prospective position in milliseconds if the current timeline is empty.

abstract Timeline

Returns the current Timeline.

abstract Tracks

Returns the current tracks.

abstract DeviceInfo

Gets the device information.

abstract @IntRange(from = 0) int

Gets the current volume of the device.

abstract long

Returns the duration of the current content or ad in milliseconds, or TIME_UNSET if the duration is not known.

abstract long

Returns the maximum position for which seekToPrevious seeks to the previous , in milliseconds.

abstract MediaMetadata

Returns the current combined MediaMetadata, or EMPTY if not supported.

abstract boolean

Whether playback will proceed when getPlaybackState == STATE_READY.

abstract PlaybackParameters

Returns the currently active playback parameters.

abstract int

Returns the current playback state of the player.

abstract int

Returns the reason why playback is suppressed even though getPlayWhenReady is true, or PLAYBACK_SUPPRESSION_REASON_NONE if playback is not suppressed.

abstract @Nullable PlaybackException

Returns the error that caused playback to fail.

abstract MediaMetadata

Returns the playlist MediaMetadata, as set by setPlaylistMetadata, or EMPTY if not supported.

abstract int

Returns the current RepeatMode used for playback.

abstract long

Returns the seekBack increment.

abstract long

Returns the seekForward increment.

abstract boolean

Returns whether shuffling of media items is enabled.

abstract Size

Gets the size of the surface on which the video is rendered.

abstract long

Returns an estimate of the total buffered duration from the current position, in milliseconds.

abstract TrackSelectionParameters

Returns the parameters constraining the track selection.

abstract VideoSize

Gets the size of the video.

abstract @FloatRange(from = 0, to = 1.0) float

Returns the audio volume, with 0 being silence and 1 being unity gain (signal unchanged).

abstract void

This method is deprecated.

Use increaseDeviceVolume instead.

abstract void

Increases the volume of the device.

abstract boolean

Gets whether the device is muted or not.

abstract boolean

Whether the player is currently loading the source.

abstract boolean

Returns whether the player is currently playing an ad.

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

Moves the media item range to the new index.

abstract void

Prepares the player.

abstract void

Releases the player.

abstract void

Unregister a listener registered through addListener.

abstract void
removeMediaItems(int fromIndex, int toIndex)

Removes a range of media items from the playlist.

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

Replaces the media items at the given range of the playlist.

abstract void
setAudioAttributes(
    AudioAttributes audioAttributes,
    boolean handleAudioFocus
)

Sets the attributes for audio playback, used by the underlying audio track.

abstract void
setDeviceMuted(boolean muted)

This method is deprecated.

Use setDeviceMuted instead.

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

Sets the mute state of the device.

abstract void
setDeviceVolume(@IntRange(from = 0) int volume)

This method is deprecated.

Use setDeviceVolume instead.

abstract void
setDeviceVolume(@IntRange(from = 0) int volume, @C.VolumeFlags int flags)

Sets the volume of the device with volume flags.

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

Clears the playlist and adds the specified media items.

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

Clears the playlist and adds the specified media items.

abstract void
setPlayWhenReady(boolean playWhenReady)

Sets whether playback should proceed when getPlaybackState == STATE_READY.

abstract void

Attempts to set the playback parameters.

abstract void

Sets the playlist MediaMetadata.

abstract void

Sets the RepeatMode to be used for playback.

abstract void
setShuffleModeEnabled(boolean shuffleModeEnabled)

Sets whether shuffling of media items is enabled.

abstract void

Sets the parameters constraining the track selection.

abstract void

Sets the Surface onto which video will be rendered.

abstract void

Sets the SurfaceHolder that holds the Surface onto which video will be rendered.

abstract void

Sets the SurfaceView onto which video will be rendered.

abstract void

Sets the TextureView onto which video will be rendered.

abstract void
setVolume(@FloatRange(from = 0, to = 1.0) float volume)

Sets the audio volume, valid values are between 0 (silence) and 1 (unity gain, signal unchanged), inclusive.

abstract void

Stops playback without resetting the playlist.

Protected fields

window

protected final Timeline.Window window

Protected constructors

BasePlayer

protected BasePlayer()

Public methods

addMediaItem

public final void addMediaItem(MediaItem mediaItem)

Adds a media item to the end of the playlist.

This method must only be called if COMMAND_CHANGE_MEDIA_ITEMS is available.

Parameters
MediaItem mediaItem

The MediaItem to add.

addMediaItem

public final void addMediaItem(int index, MediaItem mediaItem)

Adds a media item at the given index of the playlist.

This method must only be called if COMMAND_CHANGE_MEDIA_ITEMS is available.

Parameters
int index

The index at which to add the media item. If the index is larger than the size of the playlist, the media item is added to the end of the playlist.

MediaItem mediaItem

The MediaItem to add.

addMediaItems

public final void addMediaItems(List<MediaItem> mediaItems)

Adds a list of media items to the end of the playlist.

This method must only be called if COMMAND_CHANGE_MEDIA_ITEMS is available.

Parameters
List<MediaItem> mediaItems

The media items to add.

canAdvertiseSession

public final boolean canAdvertiseSession()

Returns whether the player can be used to advertise a media session.

BasePlayer and its descendants will return true.

clearMediaItems

public final void clearMediaItems()

Clears the playlist.

This method must only be called if COMMAND_CHANGE_MEDIA_ITEMS is available.

getBufferedPercentage

public final int getBufferedPercentage()

Returns an estimate of the percentage in the current content or ad up to which data is buffered, or 0 if no estimate is available.

getContentDuration

public final long getContentDuration()

If isPlayingAd returns true, returns the duration of the current content in milliseconds, or TIME_UNSET if the duration is not known. If there is no ad playing, the returned duration is the same as that returned by getDuration.

This method must only be called if COMMAND_GET_CURRENT_MEDIA_ITEM is available.

getCurrentLiveOffset

public final long getCurrentLiveOffset()

Returns the offset of the current playback position from the live edge in milliseconds, or TIME_UNSET if the current MediaItemisn't live or the offset is unknown.

The offset is calculated as currentTime - playbackPosition, so should usually be positive.

Note that this offset may rely on an accurate local time, so this method may return an incorrect value if the difference between system clock and server clock is unknown.

This method must only be called if COMMAND_GET_CURRENT_MEDIA_ITEM is available.

getCurrentManifest

public final @Nullable Object getCurrentManifest()

Returns the current manifest. The type depends on the type of media being played. May be null.

getCurrentMediaItem

public final @Nullable MediaItem getCurrentMediaItem()

Returns the currently playing MediaItem. May be null if the timeline is empty.

This method must only be called if COMMAND_GET_CURRENT_MEDIA_ITEM is available.

getCurrentWindowIndex

public final int getCurrentWindowIndex()

getMediaItemAt

public final MediaItem getMediaItemAt(int index)

Returns the MediaItem at the given index.

This method must only be called if COMMAND_GET_TIMELINE is available.

getMediaItemCount

public final int getMediaItemCount()

Returns the number of media items in the playlist.

This method must only be called if COMMAND_GET_TIMELINE is available.

getNextMediaItemIndex

public final int getNextMediaItemIndex()

Returns the index of the MediaItem that will be played if seekToNextMediaItem is called, which may depend on the current repeat mode and whether shuffle mode is enabled. Returns INDEX_UNSET if hasNextMediaItem is false.

Note: When the repeat mode is REPEAT_MODE_ONE, this method behaves the same as when the current repeat mode is REPEAT_MODE_OFF. See REPEAT_MODE_ONE for more details.

This method must only be called if COMMAND_GET_TIMELINE is available.

getNextWindowIndex

public final int getNextWindowIndex()

getPreviousMediaItemIndex

public final int getPreviousMediaItemIndex()

Returns the index of the MediaItem that will be played if seekToPreviousMediaItem is called, which may depend on the current repeat mode and whether shuffle mode is enabled. Returns INDEX_UNSET if hasPreviousMediaItem is false.

Note: When the repeat mode is REPEAT_MODE_ONE, this method behaves the same as when the current repeat mode is REPEAT_MODE_OFF. See REPEAT_MODE_ONE for more details.

This method must only be called if COMMAND_GET_TIMELINE is available.

getPreviousWindowIndex

public final int getPreviousWindowIndex()

hasNext

public final boolean hasNext()

hasNextMediaItem

public final boolean hasNextMediaItem()

Returns whether a next MediaItem exists, which may depend on the current repeat mode and whether shuffle mode is enabled.

Note: When the repeat mode is REPEAT_MODE_ONE, this method behaves the same as when the current repeat mode is REPEAT_MODE_OFF. See REPEAT_MODE_ONE for more details.

This method must only be called if COMMAND_GET_TIMELINE is available.

hasNextWindow

public final boolean hasNextWindow()

hasPreviousMediaItem

public final boolean hasPreviousMediaItem()

Returns whether a previous media item exists, which may depend on the current repeat mode and whether shuffle mode is enabled.

Note: When the repeat mode is REPEAT_MODE_ONE, this method behaves the same as when the current repeat mode is REPEAT_MODE_OFF. See REPEAT_MODE_ONE for more details.

This method must only be called if COMMAND_GET_TIMELINE is available.

isCommandAvailable

public final boolean isCommandAvailable(@Player.Command int command)

Returns whether the provided Command is available.

This method does not execute the command.

Parameters
@Player.Command int command

A Command.

Returns
boolean

Whether the Command is available.

isCurrentMediaItemDynamic

public final boolean isCurrentMediaItemDynamic()

Returns whether the current MediaItem is dynamic (may change when the Timeline is updated), or false if the Timeline is empty.

This method must only be called if COMMAND_GET_CURRENT_MEDIA_ITEM is available.

See also
isDynamic

isCurrentMediaItemLive

public final boolean isCurrentMediaItemLive()

Returns whether the current MediaItem is live, or false if the Timeline is empty.

This method must only be called if COMMAND_GET_CURRENT_MEDIA_ITEM is available.

See also
isLive

isCurrentMediaItemSeekable

public final boolean isCurrentMediaItemSeekable()

Returns whether the current MediaItem is seekable, or false if the is empty.

This method must only be called if COMMAND_GET_CURRENT_MEDIA_ITEM is available.

See also
isSeekable

isCurrentWindowDynamic

public final boolean isCurrentWindowDynamic()

isCurrentWindowLive

public final boolean isCurrentWindowLive()

isCurrentWindowSeekable

public final boolean isCurrentWindowSeekable()

isPlaying

public final boolean isPlaying()

Returns whether the player is playing, i.e. getCurrentPosition is advancing.

If false, then at least one of the following is true:

Returns
boolean

Whether the player is playing.

moveMediaItem

public final void moveMediaItem(int currentIndex, int newIndex)

Moves the media item at the current index to the new index.

This method must only be called if COMMAND_CHANGE_MEDIA_ITEMS is available.

Parameters
int currentIndex

The current index of the media item to move. If the index is larger than the size of the playlist, the request is ignored.

int newIndex

The new index of the media item. If the new index is larger than the size of the playlist the item is moved to the end of the playlist.

next

public final void next()

pause

public final void pause()

Pauses playback. Equivalent to setPlayWhenReady(false).

This method must only be called if COMMAND_PLAY_PAUSE is available.

play

public final void play()

Resumes playback as soon as getPlaybackState == STATE_READY. Equivalent to setPlayWhenReady(true).

This method must only be called if COMMAND_PLAY_PAUSE is available.

removeMediaItem

public final void removeMediaItem(int index)

Removes the media item at the given index of the playlist.

This method must only be called if COMMAND_CHANGE_MEDIA_ITEMS is available.

Parameters
int index

The index at which to remove the media item. If the index is larger than the size of the playlist, the request is ignored.

replaceMediaItem

public final void replaceMediaItem(int index, MediaItem mediaItem)

Replaces the media item at the given index of the playlist.

Implementations of this method may attempt to seamlessly continue playback if the currently playing media item is replaced with a compatible one (e.g. same URL, only metadata has changed).

This method must only be called if COMMAND_CHANGE_MEDIA_ITEMS is available.

Parameters
int index

The index at which to replace the media item. If the index is larger than the size of the playlist, the request is ignored.

MediaItem mediaItem

The new MediaItem.

seekBack

public final void seekBack()

Seeks back in the current MediaItem by getSeekBackIncrement milliseconds.

This method must only be called if COMMAND_SEEK_BACK is available.

seekForward

public final void seekForward()

Seeks forward in the current MediaItem by getSeekForwardIncrement milliseconds.

This method must only be called if COMMAND_SEEK_FORWARD is available.

seekTo

public final void seekTo(long positionMs)

Seeks to a position specified in milliseconds in the current MediaItem.

This method must only be called if COMMAND_SEEK_IN_CURRENT_MEDIA_ITEM is available.

Parameters
long positionMs

The seek position in the current MediaItem, or TIME_UNSET to seek to the media item's default position.

seekTo

public final void seekTo(int mediaItemIndex, long positionMs)

Seeks to a position specified in milliseconds in the specified MediaItem.

This method must only be called if COMMAND_SEEK_TO_MEDIA_ITEM is available.

Parameters
int mediaItemIndex

The index of the MediaItem. If the index is larger than the size of the playlist, the request is ignored.

long positionMs

The seek position in the specified MediaItem, or TIME_UNSET to seek to the media item's default position.

seekTo

@VisibleForTesting(otherwise = 4)
public abstract void seekTo(
    int mediaItemIndex,
    long positionMs,
    @Player.Command int seekCommand,
    boolean isRepeatingCurrentItem
)

Seeks to a position in the specified MediaItem.

Parameters
int mediaItemIndex

The index of the MediaItem. 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 INDEX_UNSET.

long positionMs

The seek position in the specified MediaItem in milliseconds, or TIME_UNSET to seek to the media item's default position. If the original seek operation did not directly specify a position, this is the most likely implied position based on the available player state.

@Player.Command int seekCommand

The Player.Command used to trigger the seek.

boolean isRepeatingCurrentItem

Whether this seeks repeats the current item.

seekToDefaultPosition

public final void seekToDefaultPosition()

Seeks to the default position associated with the current MediaItem. The position can depend on the type of media being played. For live streams it will typically be the live edge. For other streams it will typically be the start.

This method must only be called if COMMAND_SEEK_TO_DEFAULT_POSITION is available.

seekToDefaultPosition

public final void seekToDefaultPosition(int mediaItemIndex)

Seeks to the default position associated with the specified MediaItem. The position can depend on the type of media being played. For live streams it will typically be the live edge. For other streams it will typically be the start.

This method must only be called if COMMAND_SEEK_TO_MEDIA_ITEM is available.

Parameters
int mediaItemIndex

The index of the MediaItem whose associated default position should be seeked to. If the index is larger than the size of the playlist, the request is ignored.

seekToNext

public final void seekToNext()

Seeks to a later position in the current or next MediaItem (if available). More precisely:

  • If the timeline is empty or seeking is not possible, does nothing.
  • Otherwise, if a next media item exists, seeks to the default position of the next MediaItem.
  • Otherwise, if the current MediaItem is live and has not ended, seeks to the live edge of the current MediaItem.
  • Otherwise, does nothing.

This method must only be called if COMMAND_SEEK_TO_NEXT is available.

seekToNextMediaItem

public final void seekToNextMediaItem()

Seeks to the default position of the next MediaItem, which may depend on the current repeat mode and whether shuffle mode is enabled. Does nothing if hasNextMediaItem is false.

Note: When the repeat mode is REPEAT_MODE_ONE, this method behaves the same as when the current repeat mode is REPEAT_MODE_OFF. See REPEAT_MODE_ONE for more details.

This method must only be called if COMMAND_SEEK_TO_NEXT_MEDIA_ITEM is available.

seekToNextWindow

public final void seekToNextWindow()

seekToPrevious

public final void seekToPrevious()

Seeks to an earlier position in the current or previous MediaItem (if available). More precisely:

This method must only be called if COMMAND_SEEK_TO_PREVIOUS is available.

seekToPreviousMediaItem

public final void seekToPreviousMediaItem()

Seeks to the default position of the previous MediaItem, which may depend on the current repeat mode and whether shuffle mode is enabled. Does nothing if hasPreviousMediaItem is false.

Note: When the repeat mode is REPEAT_MODE_ONE, this method behaves the same as when the current repeat mode is REPEAT_MODE_OFF. See REPEAT_MODE_ONE for more details.

This method must only be called if COMMAND_SEEK_TO_PREVIOUS_MEDIA_ITEM is available.

seekToPreviousWindow

public final void seekToPreviousWindow()

setMediaItem

public final void setMediaItem(MediaItem mediaItem)

Clears the playlist, adds the specified MediaItem and resets the position to the default position.

To replace a media item (possibly seamlessly) without clearing the playlist, use replaceMediaItem.

This method must only be called if COMMAND_SET_MEDIA_ITEM is available.

Parameters
MediaItem mediaItem

The new MediaItem.

setMediaItem

public final void setMediaItem(MediaItem mediaItem, boolean resetPosition)

Clears the playlist and adds the specified MediaItem.

To replace a media item (possibly seamlessly) without clearing the playlist, use replaceMediaItem.

This method must only be called if COMMAND_SET_MEDIA_ITEM is available.

Parameters
MediaItem mediaItem

The new MediaItem.

boolean resetPosition

Whether the playback position should be reset to the default position. If false, playback will start from the position defined by getCurrentMediaItemIndex and getCurrentPosition.

setMediaItem

public final void setMediaItem(MediaItem mediaItem, long startPositionMs)

Clears the playlist and adds the specified MediaItem.

To replace a media item (possibly seamlessly) without clearing the playlist, use replaceMediaItem.

This method must only be called if COMMAND_SET_MEDIA_ITEM is available.

Parameters
MediaItem mediaItem

The new MediaItem.

long startPositionMs

The position in milliseconds to start playback from. If TIME_UNSET is passed, the default position of the given MediaItem is used.

setMediaItems

public final void setMediaItems(List<MediaItem> mediaItems)

Clears the playlist, adds the specified media items and resets the position to the default position.

To replace a span of media items (possibly seamlessly) without clearing the playlist, use replaceMediaItems.

This method must only be called if COMMAND_CHANGE_MEDIA_ITEMS is available.

Parameters
List<MediaItem> mediaItems

The new media items.

setPlaybackSpeed

public final void setPlaybackSpeed(float speed)

Changes the rate at which playback occurs. The pitch is not changed.

This is equivalent to setPlaybackParameters(getPlaybackParameters().withSpeed(speed)).

This method must only be called if COMMAND_SET_SPEED_AND_PITCH is available.

Parameters
float speed

The linear factor by which playback will be sped up. Must be higher than 0. 1 is normal speed, 2 is twice as fast, 0.5 is half normal speed.