BasePlayer
@UnstableApi
abstract class BasePlayer : Player
RemoteCastPlayer |
|
SimpleBasePlayer |
A base implementation for |
SimpleExoPlayer |
This class is deprecated. Use |
StubPlayer |
An abstract |
CompositionPlayer |
A |
FakePlayer |
A fake |
ForwardingSimpleBasePlayer |
A |
StubExoPlayer |
An abstract |
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 |
addMediaItems(mediaItems: (Mutable)List<MediaItem!>!)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 |
Long |
Returns the offset of the current playback position from the live edge in milliseconds, or |
Any? |
Returns the current manifest. |
MediaItem? |
Returns the currently playing |
Int |
This function is deprecated. Use |
MediaItem! |
getMediaItemAt(index: Int)Returns the |
Int |
Returns the number of |
Int |
Returns the index of the |
Int |
This function is deprecated. Use |
Int |
Returns the index of the |
Int |
This function is deprecated. Use |
Boolean |
Returns whether a next |
Boolean |
Returns whether a previous media item exists, which may depend on the current repeat mode and whether shuffle mode is enabled. |
Boolean |
isCommandAvailable(@Player.Command command: Int)Returns whether the provided |
Boolean |
Returns whether the current |
Boolean |
Returns whether the current |
Boolean |
Returns whether the current |
Boolean |
This function is deprecated. Use |
Boolean |
This function is deprecated. Use |
Boolean |
This function is deprecated. Use |
Boolean |
Returns whether the player is playing, i.e. |
Unit |
moveMediaItem(currentIndex: Int, newIndex: Int)Moves the media item at the current index to the new index. |
Unit |
pause()Pauses playback. |
Unit |
play()Resumes playback as soon as |
Unit |
removeMediaItem(index: Int)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 |
seekBack()Seeks back in the current |
Unit |
Seeks forward in the current |
Unit |
Seeks to a position specified in milliseconds in the current |
Unit |
Seeks to a position specified in milliseconds in the specified |
Unit |
Seeks to the default position associated with the current |
Unit |
seekToDefaultPosition(mediaItemIndex: Int)Seeks to the default position associated with the specified |
Unit |
Seeks to a later position in the current or next |
Unit |
Seeks to the default position of the next |
Unit |
Seeks to an earlier position in the current or previous |
Unit |
Seeks to the default position of the previous |
Unit |
setMediaItem(mediaItem: MediaItem!)Clears the playlist, adds the specified |
Unit |
setMediaItem(mediaItem: MediaItem!, resetPosition: Boolean)Clears the playlist and adds the specified |
Unit |
setMediaItem(mediaItem: MediaItem!, startPositionMs: Long)Clears the playlist and adds the specified |
Unit |
setMediaItems(mediaItems: (Mutable)List<MediaItem!>!)Clears the playlist, adds the specified |
Unit |
setPlaybackSpeed(speed: Float)Changes the rate at which playback occurs. |
Protected functions |
|
|---|---|
abstract Unit |
@ForOverrideSeeks to a position in the specified |
Protected properties |
|
|---|---|
Timeline.Window! |
Inherited Constants |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Inherited functions |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Protected constructors
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.
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.
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 |
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.
| See also | |
|---|---|
onMediaItemTransition |
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.
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.
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.
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 |
| See also | |
|---|---|
onAvailableCommandsChanged |
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 Timeline is empty.
This method must only be called if COMMAND_GET_CURRENT_MEDIA_ITEM is available.
| See also | |
|---|---|
isSeekable |
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:
- The
playback stateis notready. - There is no
intention to play. - Playback is
suppressed for other reasons.
| Returns | |
|---|---|
Boolean |
Whether the player is playing. |
| See also | |
|---|---|
onIsPlayingChanged |
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. |
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.
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 |
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 |
positionMs: Long |
The seek position in the specified |
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.
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 nextMediaItem. - Otherwise, if the current
MediaItemisliveand has not ended, seeks to the live edge of the currentMediaItem. - 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.
seekToPrevious
fun seekToPrevious(): Unit
Seeks to an earlier position in the current or previous MediaItem (if available). More precisely:
- If the timeline is empty or seeking is not possible, does nothing.
- Otherwise, if the current
MediaItemisliveandunseekable, then:- If
a previous media item exists, seeks to the default position of the previous media item. - Otherwise, does nothing.
- If
- Otherwise, if
a previous media item existsand thecurrent positionis less thangetMaxSeekToPreviousPosition, seeks to the default position of the previousMediaItem. - Otherwise, seeks to 0 in the current
MediaItem.
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.
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.
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 |
resetPosition: Boolean |
Whether the playback position should be reset to the default position. If false, playback will start from the position defined by |
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 |
startPositionMs: Long |
The position in milliseconds to start playback from. If |
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 |
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 functions
seekTo
@ForOverride
protected 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 |
positionMs: Long |
The seek position in the specified |
@Player.Command seekCommand: Int |
The |
isRepeatingCurrentItem: Boolean |
Whether this seeks repeats the current item. |