Player
CastPlayer
, SimpleExoPlayer
, StubExoPlayer
public 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, wait
addListener, 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, stop
protected final Timeline.Window window
public void setMediaItem(MediaItem mediaItem)
Player
MediaItem
and resets the position to the
default position.setMediaItem
in interface Player
mediaItem
- The new MediaItem
.public void setMediaItem(MediaItem mediaItem, long startPositionMs)
Player
MediaItem
.setMediaItem
in interface Player
mediaItem
- The new MediaItem
.startPositionMs
- The position in milliseconds to start playback from.public void setMediaItem(MediaItem mediaItem, boolean resetPosition)
Player
MediaItem
.setMediaItem
in interface Player
mediaItem
- 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)
Player
MediaItems
and resets the position to
the default position.setMediaItems
in interface Player
mediaItems
- The new MediaItems
.public void addMediaItem(int index, MediaItem mediaItem)
Player
addMediaItem
in interface Player
index
- The index at which to add the item.mediaItem
- The MediaItem
to add.public void addMediaItem(MediaItem mediaItem)
Player
addMediaItem
in interface Player
mediaItem
- The MediaItem
to add.public void moveMediaItem(int currentIndex, int newIndex)
Player
moveMediaItem
in interface Player
currentIndex
- 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)
Player
removeMediaItem
in interface Player
index
- The index at which to remove the media item.public final void play()
Player
Player.getPlaybackState()
== Player.STATE_READY
. Equivalent to
setPlayWhenReady(true)
.public final void pause()
Player
setPlayWhenReady(false)
.public final boolean isPlaying()
Player
Player.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 Player
Player.EventListener.onIsPlayingChanged(boolean)
public final void seekToDefaultPosition()
Player
seekToDefaultPosition
in interface Player
public final void seekToDefaultPosition(int windowIndex)
Player
seekToDefaultPosition
in interface Player
windowIndex
- The index of the window whose associated default position should be seeked
to.public final void seekTo(long positionMs)
Player
seekTo
in interface Player
positionMs
- The seek position in the current window, or C.TIME_UNSET
to seek to
the window's default position.public final boolean hasPrevious()
Player
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.
hasPrevious
in interface Player
public final void previous()
Player
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.
public final boolean hasNext()
Player
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 next()
Player
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.
public final void stop()
Player
Player.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()
Player
Player.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 Player
public final int getPreviousWindowIndex()
Player
Player.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()
Player
getCurrentMediaItem
in interface Player
Player.EventListener.onMediaItemTransition(MediaItem, int)
public int getMediaItemCount()
Player
media items
in the playlist.getMediaItemCount
in interface Player
public MediaItem getMediaItemAt(int index)
Player
MediaItem
at the given index.getMediaItemAt
in interface Player
@Nullable public final Object getCurrentManifest()
Player
getCurrentManifest
in interface Player
public final int getBufferedPercentage()
Player
getBufferedPercentage
in interface Player
public final boolean isCurrentWindowDynamic()
Player
false
if the Timeline
is
empty.isCurrentWindowDynamic
in interface Player
Timeline.Window.isDynamic
public final boolean isCurrentWindowLive()
Player
false
if the Timeline
is empty.isCurrentWindowLive
in interface Player
Timeline.Window.isLive()
public final long getCurrentLiveOffset()
Player
C.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 Player
public final boolean isCurrentWindowSeekable()
Player
false
if the Timeline
is
empty.isCurrentWindowSeekable
in interface Player
Timeline.Window.isSeekable
public final long getContentDuration()
Player
Player.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