BasePlayer
@UnstableApi
public abstract class BasePlayer implements 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 fields |
|
|---|---|
final Timeline.Window |
Protected constructors |
|---|
Public methods |
|
|---|---|
final void |
addMediaItem(MediaItem mediaItem)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 |
addMediaItems(List<MediaItem> mediaItems)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 |
final long |
Returns the offset of the current playback position from the live edge in milliseconds, or |
final @Nullable Object |
Returns the current manifest. |
final @Nullable MediaItem |
Returns the currently playing |
final int |
This method is deprecated. Use |
final MediaItem |
getMediaItemAt(int index)Returns the |
final int |
Returns the number of |
final int |
Returns the index of the |
final int |
This method is deprecated. Use |
final int |
Returns the index of the |
final int |
This method is deprecated. Use |
final boolean |
Returns whether a next |
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 |
isCommandAvailable(@Player.Command int command)Returns whether the provided |
final boolean |
Returns whether the current |
final boolean |
Returns whether the current |
final boolean |
Returns whether the current |
final boolean |
This method is deprecated. Use |
final boolean |
This method is deprecated. Use |
final boolean |
This method is deprecated. Use |
final boolean |
Returns whether the player is playing, i.e. |
final void |
moveMediaItem(int currentIndex, int newIndex)Moves the media item at the current index to the new index. |
final void |
pause()Pauses playback. |
final void |
play()Resumes playback as soon as |
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 |
seekBack()Seeks back in the current |
final void |
Seeks forward in the current |
final void |
seekTo(long positionMs)Seeks to a position specified in milliseconds in the current |
final void |
seekTo(int mediaItemIndex, long positionMs)Seeks to a position specified in milliseconds in the specified |
final void |
Seeks to the default position associated with the current |
final void |
seekToDefaultPosition(int mediaItemIndex)Seeks to the default position associated with the specified |
final void |
Seeks to a later position in the current or next |
final void |
Seeks to the default position of the next |
final void |
Seeks to an earlier position in the current or previous |
final void |
Seeks to the default position of the previous |
final void |
setMediaItem(MediaItem mediaItem)Clears the playlist, adds the specified |
final void |
setMediaItem(MediaItem mediaItem, boolean resetPosition)Clears the playlist and adds the specified |
final void |
setMediaItem(MediaItem mediaItem, long startPositionMs)Clears the playlist and adds the specified |
final void |
setMediaItems(List<MediaItem> mediaItems)Clears the playlist, adds the specified |
final void |
setPlaybackSpeed(float speed)Changes the rate at which playback occurs. |
Protected methods |
|
|---|---|
abstract void |
@ForOverrideSeeks to a position in the specified |
Inherited Constants |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Inherited methods |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Protected fields
Protected constructors
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.
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.
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 |
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.
| See also | |
|---|---|
onMediaItemTransition |
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.
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.
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.
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 |
| Returns | |
|---|---|
boolean |
Whether the |
| See also | |
|---|---|
onAvailableCommandsChanged |
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 Timeline is empty.
This method must only be called if COMMAND_GET_CURRENT_MEDIA_ITEM is available.
| See also | |
|---|---|
isSeekable |
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:
- 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
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. |
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.
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 |
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 |
long positionMs |
The seek position in the specified |
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 |
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 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
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.
seekToPrevious
public final void seekToPrevious()
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
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.
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.
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 |
boolean resetPosition |
Whether the playback position should be reset to the default position. If false, playback will start from the position defined by |
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 |
long startPositionMs |
The position in milliseconds to start playback from. If |
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 |
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. |
Protected methods
seekTo
@ForOverride
protected 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 |
long positionMs |
The seek position in the specified |
@Player.Command int seekCommand |
The |
boolean isRepeatingCurrentItem |
Whether this seeks repeats the current item. |