PlayerCastPlayer, SimpleExoPlayer, StubExoPlayerpublic abstract class BasePlayer extends Object implements Player
Player which implements common implementation independent methods.Player.AudioComponent, Player.DefaultEventListener, Player.DeviceComponent, Player.DiscontinuityReason, Player.EventFlags, Player.EventListener, Player.Events, Player.MediaItemTransitionReason, Player.MetadataComponent, Player.PlaybackSuppressionReason, Player.PlayWhenReadyChangeReason, Player.RepeatMode, Player.State, Player.TextComponent, Player.TimelineChangeReason, Player.VideoComponent| Modifier and Type | Field | Description |
|---|---|---|
protected Timeline.Window |
window |
DISCONTINUITY_REASON_AD_INSERTION, DISCONTINUITY_REASON_INTERNAL, DISCONTINUITY_REASON_PERIOD_TRANSITION, DISCONTINUITY_REASON_SEEK, DISCONTINUITY_REASON_SEEK_ADJUSTMENT, EVENT_IS_LOADING_CHANGED, EVENT_IS_PLAYING_CHANGED, EVENT_MEDIA_ITEM_TRANSITION, EVENT_PLAY_WHEN_READY_CHANGED, EVENT_PLAYBACK_PARAMETERS_CHANGED, EVENT_PLAYBACK_STATE_CHANGED, EVENT_PLAYBACK_SUPPRESSION_REASON_CHANGED, EVENT_PLAYER_ERROR, EVENT_POSITION_DISCONTINUITY, EVENT_REPEAT_MODE_CHANGED, EVENT_SHUFFLE_MODE_ENABLED_CHANGED, EVENT_STATIC_METADATA_CHANGED, EVENT_TIMELINE_CHANGED, EVENT_TRACKS_CHANGED, MEDIA_ITEM_TRANSITION_REASON_AUTO, MEDIA_ITEM_TRANSITION_REASON_PLAYLIST_CHANGED, MEDIA_ITEM_TRANSITION_REASON_REPEAT, MEDIA_ITEM_TRANSITION_REASON_SEEK, PLAY_WHEN_READY_CHANGE_REASON_AUDIO_BECOMING_NOISY, PLAY_WHEN_READY_CHANGE_REASON_AUDIO_FOCUS_LOSS, PLAY_WHEN_READY_CHANGE_REASON_END_OF_MEDIA_ITEM, PLAY_WHEN_READY_CHANGE_REASON_REMOTE, PLAY_WHEN_READY_CHANGE_REASON_USER_REQUEST, PLAYBACK_SUPPRESSION_REASON_NONE, PLAYBACK_SUPPRESSION_REASON_TRANSIENT_AUDIO_FOCUS_LOSS, REPEAT_MODE_ALL, REPEAT_MODE_OFF, REPEAT_MODE_ONE, STATE_BUFFERING, STATE_ENDED, STATE_IDLE, STATE_READY, TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED, TIMELINE_CHANGE_REASON_SOURCE_UPDATE| Constructor | Description |
|---|---|
BasePlayer() |
| Modifier and Type | Method | Description |
|---|---|---|
void |
addMediaItem(int index,
MediaItem mediaItem) |
Adds a media item at the given index of the playlist.
|
void |
addMediaItem(MediaItem mediaItem) |
Adds a media item to the end of the playlist.
|
int |
getBufferedPercentage() |
Returns an estimate of the percentage in the current content window or ad up to which data is
buffered, or 0 if no estimate is available.
|
long |
getContentDuration() |
If
Player.isPlayingAd() returns true, returns the duration of the current content
window in milliseconds, or C.TIME_UNSET if the duration is not known. |
long |
getCurrentLiveOffset() |
Returns the offset of the current playback position from the live edge in milliseconds, or
C.TIME_UNSET if the current window isn't live or the
offset is unknown. |
Object |
getCurrentManifest() |
Returns the current manifest.
|
MediaItem |
getCurrentMediaItem() |
Returns the media item of the current window in the timeline.
|
Object |
getCurrentTag() |
Deprecated.
Use
getCurrentMediaItem() and MediaItem.PlaybackProperties.tag
instead. |
MediaItem |
getMediaItemAt(int index) |
Returns the
MediaItem at the given index. |
int |
getMediaItemCount() |
Returns the number of
media items in the playlist. |
int |
getNextWindowIndex() |
Returns the index of the window that will be played if
Player.next() is called, which may
depend on the current repeat mode and whether shuffle mode is enabled. |
int |
getPreviousWindowIndex() |
Returns the index of the window that will be played if
Player.previous() is called, which may
depend on the current repeat mode and whether shuffle mode is enabled. |
boolean |
hasNext() |
Returns whether a next window exists, which may depend on the current repeat mode and whether
shuffle mode is enabled.
|
boolean |
hasPrevious() |
Returns whether a previous window exists, which may depend on the current repeat mode and
whether shuffle mode is enabled.
|
boolean |
isCurrentWindowDynamic() |
Returns whether the current window is dynamic, or
false if the Timeline is
empty. |
boolean |
isCurrentWindowLive() |
Returns whether the current window is live, or
false if the Timeline is empty. |
boolean |
isCurrentWindowSeekable() |
Returns whether the current window is seekable, or
false if the Timeline is
empty. |
boolean |
isPlaying() |
Returns whether the player is playing, i.e.
|
void |
moveMediaItem(int currentIndex,
int newIndex) |
Moves the media item at the current index to the new index.
|
void |
next() |
Seeks to the default position of the next window, which may depend on the current repeat mode
and whether shuffle mode is enabled.
|
void |
pause() |
Pauses playback.
|
void |
play() |
Resumes playback as soon as
Player.getPlaybackState() == Player.STATE_READY. |
void |
previous() |
Seeks to the default position of the previous window, which may depend on the current repeat
mode and whether shuffle mode is enabled.
|
void |
removeMediaItem(int index) |
Removes the media item at the given index of the playlist.
|
void |
seekTo(long positionMs) |
Seeks to a position specified in milliseconds in the current window.
|
void |
seekToDefaultPosition() |
Seeks to the default position associated with the current window.
|
void |
seekToDefaultPosition(int windowIndex) |
Seeks to the default position associated with the specified window.
|
void |
setMediaItem(MediaItem mediaItem) |
Clears the playlist, adds the specified
MediaItem and resets the position to the
default position. |
void |
setMediaItem(MediaItem mediaItem,
boolean resetPosition) |
Clears the playlist and adds the specified
MediaItem. |
void |
setMediaItem(MediaItem mediaItem,
long startPositionMs) |
Clears the playlist and adds the specified
MediaItem. |
void |
setMediaItems(List<MediaItem> mediaItems) |
Clears the playlist, adds the specified
MediaItems and resets the position to
the default position. |
void |
stop() |
Stops playback without resetting the player.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitaddListener, addMediaItems, addMediaItems, clearMediaItems, getApplicationLooper, getAudioComponent, getBufferedPosition, getContentBufferedPosition, getContentPosition, getCurrentAdGroupIndex, getCurrentAdIndexInAdGroup, getCurrentPeriodIndex, getCurrentPosition, getCurrentStaticMetadata, getCurrentTimeline, getCurrentTrackGroups, getCurrentTrackSelections, getCurrentWindowIndex, getDeviceComponent, getDuration, getMetadataComponent, getPlaybackError, getPlaybackParameters, getPlaybackState, getPlaybackSuppressionReason, getPlayerError, getPlayWhenReady, getRendererCount, getRendererType, getRepeatMode, getShuffleModeEnabled, getTextComponent, getTotalBufferedDuration, getVideoComponent, isLoading, isPlayingAd, moveMediaItems, prepare, release, removeListener, removeMediaItems, seekTo, setMediaItems, setMediaItems, setPlaybackParameters, setPlayWhenReady, setRepeatMode, setShuffleModeEnabled, stopprotected final Timeline.Window window
public void setMediaItem(MediaItem mediaItem)
PlayerMediaItem and resets the position to the
default position.setMediaItem in interface PlayermediaItem - The new MediaItem.public void setMediaItem(MediaItem mediaItem, long startPositionMs)
PlayerMediaItem.setMediaItem in interface PlayermediaItem - The new MediaItem.startPositionMs - The position in milliseconds to start playback from.public void setMediaItem(MediaItem mediaItem, boolean resetPosition)
PlayerMediaItem.setMediaItem in interface PlayermediaItem - The new MediaItem.resetPosition - Whether the playback position should be reset to the default position. If
false, playback will start from the position defined by Player.getCurrentWindowIndex()
and Player.getCurrentPosition().public void setMediaItems(List<MediaItem> mediaItems)
PlayerMediaItems and resets the position to
the default position.setMediaItems in interface PlayermediaItems - The new MediaItems.public void addMediaItem(int index,
MediaItem mediaItem)
PlayeraddMediaItem in interface Playerindex - The index at which to add the item.mediaItem - The MediaItem to add.public void addMediaItem(MediaItem mediaItem)
PlayeraddMediaItem in interface PlayermediaItem - The MediaItem to add.public void moveMediaItem(int currentIndex,
int newIndex)
PlayermoveMediaItem in interface PlayercurrentIndex - The current index of the media item to move.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.public void removeMediaItem(int index)
PlayerremoveMediaItem in interface Playerindex - The index at which to remove the media item.public final void play()
PlayerPlayer.getPlaybackState() == Player.STATE_READY. Equivalent to
setPlayWhenReady(true).public final void pause()
PlayersetPlayWhenReady(false).public final boolean isPlaying()
PlayerPlayer.getContentPosition() is advancing.
If false, then at least one of the following is true:
playback state is not ready.
intention to play.
suppressed for other reasons.
isPlaying in interface PlayerPlayer.EventListener.onIsPlayingChanged(boolean)public final void seekToDefaultPosition()
PlayerseekToDefaultPosition in interface Playerpublic final void seekToDefaultPosition(int windowIndex)
PlayerseekToDefaultPosition in interface PlayerwindowIndex - The index of the window whose associated default position should be seeked
to.public final void seekTo(long positionMs)
PlayerseekTo in interface PlayerpositionMs - The seek position in the current window, or C.TIME_UNSET to seek to
the window's default position.public final boolean hasPrevious()
PlayerNote: When the repeat mode is Player.REPEAT_MODE_ONE, this method behaves the same as when
the current repeat mode is Player.REPEAT_MODE_OFF. See Player.REPEAT_MODE_ONE for more
details.
hasPrevious in interface Playerpublic final void previous()
PlayerPlayer.hasPrevious() is
false.
Note: When the repeat mode is Player.REPEAT_MODE_ONE, this method behaves the same as when
the current repeat mode is Player.REPEAT_MODE_OFF. See Player.REPEAT_MODE_ONE for more
details.
public final boolean hasNext()
PlayerNote: When the repeat mode is Player.REPEAT_MODE_ONE, this method behaves the same as when
the current repeat mode is Player.REPEAT_MODE_OFF. See Player.REPEAT_MODE_ONE for more
details.
public final void next()
PlayerPlayer.hasNext() is false.
Note: When the repeat mode is Player.REPEAT_MODE_ONE, this method behaves the same as when
the current repeat mode is Player.REPEAT_MODE_OFF. See Player.REPEAT_MODE_ONE for more
details.
public final void stop()
PlayerPlayer.pause() rather than this method if
the intention is to pause playback.
Calling this method will cause the playback state to transition to Player.STATE_IDLE. The
player instance can still be used, and Player.release() must still be called on the player if
it's no longer required.
Calling this method does not clear the playlist, reset the playback position or the playback error.
public final int getNextWindowIndex()
PlayerPlayer.next() is called, which may
depend on the current repeat mode and whether shuffle mode is enabled. Returns C.INDEX_UNSET if Player.hasNext() is false.
Note: When the repeat mode is Player.REPEAT_MODE_ONE, this method behaves the same as when
the current repeat mode is Player.REPEAT_MODE_OFF. See Player.REPEAT_MODE_ONE for more
details.
getNextWindowIndex in interface Playerpublic final int getPreviousWindowIndex()
PlayerPlayer.previous() is called, which may
depend on the current repeat mode and whether shuffle mode is enabled. Returns C.INDEX_UNSET if Player.hasPrevious() is false.
Note: When the repeat mode is Player.REPEAT_MODE_ONE, this method behaves the same as when
the current repeat mode is Player.REPEAT_MODE_OFF. See Player.REPEAT_MODE_ONE for more
details.
getPreviousWindowIndex in interface Player@Deprecated @Nullable public final Object getCurrentTag()
getCurrentMediaItem() and MediaItem.PlaybackProperties.tag
instead.getCurrentTag in interface Player@Nullable public final MediaItem getCurrentMediaItem()
PlayergetCurrentMediaItem in interface PlayerPlayer.EventListener.onMediaItemTransition(MediaItem, int)public int getMediaItemCount()
Playermedia items in the playlist.getMediaItemCount in interface Playerpublic MediaItem getMediaItemAt(int index)
PlayerMediaItem at the given index.getMediaItemAt in interface Player@Nullable public final Object getCurrentManifest()
PlayergetCurrentManifest in interface Playerpublic final int getBufferedPercentage()
PlayergetBufferedPercentage in interface Playerpublic final boolean isCurrentWindowDynamic()
Playerfalse if the Timeline is
empty.isCurrentWindowDynamic in interface PlayerTimeline.Window.isDynamicpublic final boolean isCurrentWindowLive()
Playerfalse if the Timeline is empty.isCurrentWindowLive in interface PlayerTimeline.Window.isLive()public final long getCurrentLiveOffset()
PlayerC.TIME_UNSET if the current window isn'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.
getCurrentLiveOffset in interface Playerpublic final boolean isCurrentWindowSeekable()
Playerfalse if the Timeline is
empty.isCurrentWindowSeekable in interface PlayerTimeline.Window.isSeekablepublic final long getContentDuration()
PlayerPlayer.isPlayingAd() returns true, returns the duration of the current content
window in milliseconds, or C.TIME_UNSET if the duration is not known. If there is no ad
playing, the returned duration is the same as that returned by Player.getDuration().getContentDuration in interface Player