@UnstableApi
abstract class BasePlayer : 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 constructors

Public functions

Unit
addMediaItem(mediaItem: MediaItem!)

Adds a media item to the end of the playlist.

Unit
addMediaItem(index: Int, mediaItem: MediaItem!)

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

Unit

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

Boolean

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

Unit

Clears the playlist.

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.

Long

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

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.

Any?

Returns the current manifest.

MediaItem?

Returns the currently playing MediaItem.

Int

This function is deprecated.

Use getCurrentMediaItemIndex instead.

MediaItem!

Returns the MediaItem at the given index.

Int

Returns the number of media items in the playlist.

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.

Int

This function is deprecated.

Use getNextMediaItemIndex instead.

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.

Int

This function is deprecated.

Use getPreviousMediaItemIndex instead.

Boolean

This function is deprecated.

Use hasNextMediaItem instead.

Boolean

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

Boolean

This function is deprecated.

Use hasNextMediaItem instead.

Boolean

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

Boolean

Returns whether the provided Command is available.

Boolean

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

Boolean

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

Boolean

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

Boolean

This function is deprecated.

Use isCurrentMediaItemDynamic instead.

Boolean

This function is deprecated.

Use isCurrentMediaItemLive instead.

Boolean

This function is deprecated.

Use isCurrentMediaItemSeekable instead.

Boolean

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

Unit
moveMediaItem(currentIndex: Int, newIndex: Int)

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

Unit

This function is deprecated.

Use seekToNextMediaItem instead.

Unit

Pauses playback.

Unit

Resumes playback as soon as getPlaybackState == STATE_READY.

Unit

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

Unit
replaceMediaItem(index: Int, mediaItem: MediaItem!)

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

Unit

Seeks back in the current MediaItem by getSeekBackIncrement milliseconds.

Unit

Seeks forward in the current MediaItem by getSeekForwardIncrement milliseconds.

Unit
seekTo(positionMs: Long)

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

Unit
seekTo(mediaItemIndex: Int, positionMs: Long)

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

abstract Unit
@VisibleForTesting(otherwise = 4)
seekTo(
    mediaItemIndex: Int,
    positionMs: Long,
    @Player.Command seekCommand: Int,
    isRepeatingCurrentItem: Boolean
)

Seeks to a position in the specified MediaItem.

Unit

Seeks to the default position associated with the current MediaItem.

Unit
seekToDefaultPosition(mediaItemIndex: Int)

Seeks to the default position associated with the specified MediaItem.

Unit

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

Unit

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

Unit

This function is deprecated.

Use seekToNextMediaItem instead.

Unit

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

Unit

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

Unit

This function is deprecated.

Use seekToPreviousMediaItem instead.

Unit
setMediaItem(mediaItem: MediaItem!)

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

Unit
setMediaItem(mediaItem: MediaItem!, resetPosition: Boolean)

Clears the playlist and adds the specified MediaItem.

Unit
setMediaItem(mediaItem: MediaItem!, startPositionMs: Long)

Clears the playlist and adds the specified MediaItem.

Unit

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

Unit

Changes the rate at which playback occurs.

Protected properties

Timeline.Window!

Inherited Constants

From androidx.media3.common.Player
const Int

This property is deprecated.

Use COMMAND_ADJUST_DEVICE_VOLUME_WITH_FLAGS instead.

const Int

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

const Int

Command to change the media items in the playlist.

const Int

Command to get the player current AudioAttributes.

const Int

Command to get information about the currently playing MediaItem.

const Int

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

const Int

This property is deprecated.

Use COMMAND_GET_METADATA instead.

const Int

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

const Int

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

const Int

Command to get the information about the current timeline.

const Int

Command to get details of the current track selection.

const Int

Command to get the player volume.

const Int

Represents an invalid Command.

const Int

Command to start, pause or resume playback.

const Int

Command to prepare the player.

const Int

Command to release the player.

const Int

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

const Int

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

const Int

Command to seek anywhere inside the current MediaItem.

const Int

This property is deprecated.

Use COMMAND_SEEK_IN_CURRENT_MEDIA_ITEM instead.

const Int

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

const Int

Command to seek anywhere in any MediaItem.

const Int

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

const Int

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

const Int

This property is deprecated.

Use COMMAND_SEEK_TO_NEXT_MEDIA_ITEM instead.

const Int

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

const Int

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

const Int

This property is deprecated.

Use COMMAND_SEEK_TO_PREVIOUS_MEDIA_ITEM instead.

const Int

This property is deprecated.

Use COMMAND_SEEK_TO_MEDIA_ITEM instead.

const Int

Command to set the player's audio attributes.

const Int

This property is deprecated.

Use COMMAND_SET_DEVICE_VOLUME_WITH_FLAGS instead.

const Int

Command to set the device volume with volume flags.

const Int

Command to set a MediaItem.

const Int

This property is deprecated.

Use COMMAND_SET_PLAYLIST_METADATA instead.

const Int

Command to set the playlist metadata.

const Int

Command to set the repeat mode.

const Int

Command to enable shuffling.

const Int

Command to set the playback speed and pitch.

const Int

Command to set the player's track selection parameters.

const Int

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

const Int

Command to set the player volume.

const Int

Command to stop playback.

const Int

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

const Int

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

const Int

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

const Int

Seek within the current period or to another period.

const Int

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

const Int

Discontinuity introduced by a skipped silence.

const Int

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

const Int

getAudioAttributes changed.

const Int

The audio session id was set.

const Int

isCommandAvailable changed for at least one Command.

const Int

getCurrentCues changed.

const Int

getDeviceInfo changed.

const Int

getDeviceVolume changed.

const Int

isLoading ()} changed.

const Int

isPlaying changed.

const Int

getMaxSeekToPreviousPosition changed.

const Int

getCurrentMediaItem changed or the player started repeating the current item.

const Int

getMediaMetadata changed.

const Int

Metadata associated with the current playback time changed.

const Int

getPlaybackParameters changed.

const Int

getPlaybackState changed.

const Int

getPlaybackSuppressionReason changed.

const Int

getPlayerError changed.

const Int

getPlaylistMetadata changed.

const Int

getPlayWhenReady changed.

const Int

A position discontinuity occurred.

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

const Int

getRepeatMode changed.

const Int

getSeekBackIncrement changed.

const Int

getSeekForwardIncrement changed.

const Int

getShuffleModeEnabled changed.

const Int

Skipping silences in the audio stream is enabled or disabled.

const Int

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

const Int

getCurrentTimeline changed.

const Int

getCurrentTracks changed.

const Int

getTrackSelectionParameters changed.

const Int

getVideoSize changed.

const Int

getVolume changed.

const Int

Playback has automatically transitioned to the next media item.

const Int

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

const Int

The media item has been repeated.

const Int

A seek to another media item has occurred.

const Int

Playback is not suppressed.

const Int

Playback is suppressed due to transient audio focus loss.

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

const Int

This property is deprecated.

Use PLAYBACK_SUPPRESSION_REASON_UNSUITABLE_AUDIO_OUTPUT instead.

const Int

Playback has been paused to avoid becoming noisy.

const Int

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

const Int

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

const Int

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

const Int

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

const Int

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

const Int

Repeats the entire timeline infinitely.

const Int

Normal playback without repetition.

const Int

Repeats the currently playing MediaItem infinitely during ongoing playback.

const Int

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

const Int

The player has finished playing the media.

const Int

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

const Int

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

const Int

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

const Int

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

Inherited functions

From androidx.media3.common.Player
abstract Unit

Registers a listener to receive all events from the player.

abstract Unit
addMediaItems(index: Int, mediaItems: (Mutable)List<MediaItem!>!)

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

abstract Unit

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

abstract Unit

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

abstract Unit

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

abstract Unit

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

abstract Unit

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

abstract Unit

This function is deprecated.

Use decreaseDeviceVolume instead.

abstract Unit

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 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 Unit

This function is deprecated.

Use increaseDeviceVolume instead.

abstract Unit

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 Unit
moveMediaItems(fromIndex: Int, toIndex: Int, newIndex: Int)

Moves the media item range to the new index.

abstract Unit

Prepares the player.

abstract Unit

Releases the player.

abstract Unit

Unregister a listener registered through addListener.

abstract Unit
removeMediaItems(fromIndex: Int, toIndex: Int)

Removes a range of media items from the playlist.

abstract Unit
replaceMediaItems(
    fromIndex: Int,
    toIndex: Int,
    mediaItems: (Mutable)List<MediaItem!>!
)

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

abstract Unit
setAudioAttributes(
    audioAttributes: AudioAttributes!,
    handleAudioFocus: Boolean
)

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

abstract Unit

This function is deprecated.

Use setDeviceMuted instead.

abstract Unit

Sets the mute state of the device.

abstract Unit
setDeviceVolume(volume: @IntRange(from = 0) Int)

This function is deprecated.

Use setDeviceVolume instead.

abstract Unit
setDeviceVolume(volume: @IntRange(from = 0) Int, @C.VolumeFlags flags: Int)

Sets the volume of the device with volume flags.

abstract Unit
setMediaItems(
    mediaItems: (Mutable)List<MediaItem!>!,
    resetPosition: Boolean
)

Clears the playlist and adds the specified media items.

abstract Unit
setMediaItems(
    mediaItems: (Mutable)List<MediaItem!>!,
    startIndex: Int,
    startPositionMs: Long
)

Clears the playlist and adds the specified media items.

abstract Unit
setPlayWhenReady(playWhenReady: Boolean)

Sets whether playback should proceed when getPlaybackState == STATE_READY.

abstract Unit

Attempts to set the playback parameters.

abstract Unit

Sets the playlist MediaMetadata.

abstract Unit

Sets the RepeatMode to be used for playback.

abstract Unit
setShuffleModeEnabled(shuffleModeEnabled: Boolean)

Sets whether shuffling of media items is enabled.

abstract Unit

Sets the parameters constraining the track selection.

abstract Unit

Sets the Surface onto which video will be rendered.

abstract Unit

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

abstract Unit

Sets the SurfaceView onto which video will be rendered.

abstract Unit

Sets the TextureView onto which video will be rendered.

abstract Unit
setVolume(volume: @FloatRange(from = 0, to = 1.0) Float)

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

abstract Unit

Stops playback without resetting the playlist.

Protected constructors

BasePlayer

protected BasePlayer()

Public functions

addMediaItem

fun addMediaItem(mediaItem: MediaItem!): Unit

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

fun addMediaItem(index: Int, mediaItem: MediaItem!): Unit

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
index: Int

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

fun addMediaItems(mediaItems: (Mutable)List<MediaItem!>!): Unit

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
mediaItems: (Mutable)List<MediaItem!>!

The media items to add.

canAdvertiseSession

fun canAdvertiseSession(): Boolean

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

BasePlayer and its descendants will return true.

clearMediaItems

fun clearMediaItems(): Unit

Clears the playlist.

This method must only be called if COMMAND_CHANGE_MEDIA_ITEMS is available.

getBufferedPercentage

fun getBufferedPercentage(): 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.

getContentDuration

fun getContentDuration(): Long

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

fun getCurrentLiveOffset(): 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.

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

fun getCurrentManifest(): Any?

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

getCurrentMediaItem

fun getCurrentMediaItem(): MediaItem?

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

fun getCurrentWindowIndex(): Int

getMediaItemAt

fun getMediaItemAt(index: Int): MediaItem!

Returns the MediaItem at the given index.

This method must only be called if COMMAND_GET_TIMELINE is available.

getMediaItemCount

fun getMediaItemCount(): Int

Returns the number of media items in the playlist.

This method must only be called if COMMAND_GET_TIMELINE is available.

getNextMediaItemIndex

fun getNextMediaItemIndex(): 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. 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

fun getNextWindowIndex(): Int

getPreviousMediaItemIndex

fun getPreviousMediaItemIndex(): 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. 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

fun getPreviousWindowIndex(): Int

hasNext

fun hasNext(): Boolean

hasNextMediaItem

fun hasNextMediaItem(): Boolean

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

fun hasNextWindow(): Boolean

hasPreviousMediaItem

fun hasPreviousMediaItem(): Boolean

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

fun isCommandAvailable(@Player.Command command: Int): Boolean

Returns whether the provided Command is available.

This method does not execute the command.

Parameters
@Player.Command command: Int

A Command.

Returns
Boolean

Whether the Command is available.

isCurrentMediaItemDynamic

fun isCurrentMediaItemDynamic(): Boolean

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

fun isCurrentMediaItemLive(): Boolean

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

fun isCurrentMediaItemSeekable(): Boolean

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

fun isCurrentWindowDynamic(): Boolean

isCurrentWindowLive

fun isCurrentWindowLive(): Boolean

isCurrentWindowSeekable

fun isCurrentWindowSeekable(): Boolean

isPlaying

fun isPlaying(): Boolean

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

fun moveMediaItem(currentIndex: Int, newIndex: Int): Unit

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
currentIndex: Int

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

newIndex: Int

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

fun next(): Unit

pause

fun pause(): Unit

Pauses playback. Equivalent to setPlayWhenReady(false).

This method must only be called if COMMAND_PLAY_PAUSE is available.

play

fun play(): Unit

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

fun removeMediaItem(index: Int): Unit

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
index: Int

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

fun replaceMediaItem(index: Int, mediaItem: MediaItem!): Unit

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
index: Int

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

fun seekBack(): Unit

Seeks back in the current MediaItem by getSeekBackIncrement milliseconds.

This method must only be called if COMMAND_SEEK_BACK is available.

seekForward

fun seekForward(): Unit

Seeks forward in the current MediaItem by getSeekForwardIncrement milliseconds.

This method must only be called if COMMAND_SEEK_FORWARD is available.

seekTo

fun seekTo(positionMs: Long): Unit

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
positionMs: Long

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

seekTo

fun seekTo(mediaItemIndex: Int, positionMs: Long): Unit

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
mediaItemIndex: Int

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

positionMs: Long

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

seekTo

@VisibleForTesting(otherwise = 4)
abstract fun seekTo(
    mediaItemIndex: Int,
    positionMs: Long,
    @Player.Command seekCommand: Int,
    isRepeatingCurrentItem: Boolean
): Unit

Seeks to a position in the specified MediaItem.

Parameters
mediaItemIndex: Int

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.

positionMs: Long

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 seekCommand: Int

The Player.Command used to trigger the seek.

isRepeatingCurrentItem: Boolean

Whether this seeks repeats the current item.

seekToDefaultPosition

fun seekToDefaultPosition(): Unit

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

fun seekToDefaultPosition(mediaItemIndex: Int): Unit

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
mediaItemIndex: Int

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

fun seekToNext(): Unit

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

fun seekToNextMediaItem(): Unit

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

fun seekToNextWindow(): Unit

seekToPrevious

fun seekToPrevious(): Unit

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

fun seekToPreviousMediaItem(): Unit

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

fun seekToPreviousWindow(): Unit

setMediaItem

fun setMediaItem(mediaItem: MediaItem!): Unit

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

fun setMediaItem(mediaItem: MediaItem!, resetPosition: Boolean): Unit

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.

resetPosition: Boolean

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

fun setMediaItem(mediaItem: MediaItem!, startPositionMs: Long): Unit

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.

startPositionMs: Long

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

setMediaItems

fun setMediaItems(mediaItems: (Mutable)List<MediaItem!>!): Unit

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
mediaItems: (Mutable)List<MediaItem!>!

The new media items.

setPlaybackSpeed

fun setPlaybackSpeed(speed: Float): Unit

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
speed: Float

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.

Protected properties

window

protected val windowTimeline.Window!