ExoPlayer
BasePlayer
, CastPlayer
, SimpleExoPlayer
, StubExoPlayer
public interface Player
Some important properties of media players that implement this interface are:
Timeline
representing the structure of the media being played,
which can be obtained by calling getCurrentTimeline()
.
TrackGroupArray
defining the currently available tracks, which
can be obtained by calling getCurrentTrackGroups()
.
getRendererCount()
and getRendererType(int)
.
TrackSelectionArray
defining which of the currently available
tracks are selected to be rendered by each renderer. This can be obtained by calling getCurrentTrackSelections()
}.
Modifier and Type | Interface | Description |
---|---|---|
static interface |
Player.AudioComponent |
The audio component of a
Player . |
static class |
Player.DefaultEventListener |
Deprecated.
Use
Player.EventListener interface directly for selective overrides as all methods
are implemented as no-op default methods. |
static interface |
Player.DeviceComponent |
The device component of a
Player . |
static interface |
Player.DiscontinuityReason |
Reasons for position discontinuities.
|
static interface |
Player.EventFlags |
Events that can be reported via
Player.EventListener.onEvents(Player, Events) . |
static interface |
Player.EventListener |
Listener of changes in player state.
|
static class |
Player.Events |
A set of
Player.EventFlags . |
static interface |
Player.MediaItemTransitionReason |
Reasons for media item transitions.
|
static interface |
Player.MetadataComponent |
The metadata component of a
Player . |
static interface |
Player.PlaybackSuppressionReason |
Reason why playback is suppressed even though
getPlayWhenReady() is true . |
static interface |
Player.PlayWhenReadyChangeReason |
Reasons for
playWhenReady changes. |
static interface |
Player.RepeatMode |
Repeat modes for playback.
|
static interface |
Player.State |
Playback state.
|
static interface |
Player.TextComponent |
The text component of a
Player . |
static interface |
Player.TimelineChangeReason |
Reasons for timeline changes.
|
static interface |
Player.VideoComponent |
The video component of a
Player . |
Modifier and Type | Field | Description |
---|---|---|
static int |
DISCONTINUITY_REASON_AD_INSERTION |
Discontinuity to or from an ad within one period in the timeline.
|
static int |
DISCONTINUITY_REASON_INTERNAL |
Discontinuity introduced internally by the source.
|
static int |
DISCONTINUITY_REASON_PERIOD_TRANSITION |
Automatic playback transition from one period in the timeline to the next.
|
static int |
DISCONTINUITY_REASON_SEEK |
Seek within the current period or to another period.
|
static int |
DISCONTINUITY_REASON_SEEK_ADJUSTMENT |
Seek adjustment due to being unable to seek to the requested position or because the seek was
permitted to be inexact.
|
static int |
EVENT_IS_LOADING_CHANGED |
isLoading() ()} changed. |
static int |
EVENT_IS_PLAYING_CHANGED |
isPlaying() changed. |
static int |
EVENT_MEDIA_ITEM_TRANSITION |
getCurrentMediaItem() changed or the player started repeating the current item. |
static int |
EVENT_PLAY_WHEN_READY_CHANGED |
getPlayWhenReady() changed. |
static int |
EVENT_PLAYBACK_PARAMETERS_CHANGED |
getPlaybackParameters() changed. |
static int |
EVENT_PLAYBACK_STATE_CHANGED |
getPlaybackState() changed. |
static int |
EVENT_PLAYBACK_SUPPRESSION_REASON_CHANGED |
getPlaybackSuppressionReason() changed. |
static int |
EVENT_PLAYER_ERROR |
getPlayerError() changed. |
static int |
EVENT_POSITION_DISCONTINUITY |
A position discontinuity occurred.
|
static int |
EVENT_REPEAT_MODE_CHANGED |
getRepeatMode() changed. |
static int |
EVENT_SHUFFLE_MODE_ENABLED_CHANGED |
getShuffleModeEnabled() changed. |
static int |
EVENT_STATIC_METADATA_CHANGED |
getCurrentStaticMetadata() changed. |
static int |
EVENT_TIMELINE_CHANGED |
getCurrentTimeline() changed. |
static int |
EVENT_TRACKS_CHANGED |
getCurrentTrackGroups() or getCurrentTrackSelections() changed. |
static int |
MEDIA_ITEM_TRANSITION_REASON_AUTO |
Playback has automatically transitioned to the next media item.
|
static int |
MEDIA_ITEM_TRANSITION_REASON_PLAYLIST_CHANGED |
The current media item has changed because of a change in the playlist.
|
static int |
MEDIA_ITEM_TRANSITION_REASON_REPEAT |
The media item has been repeated.
|
static int |
MEDIA_ITEM_TRANSITION_REASON_SEEK |
A seek to another media item has occurred.
|
static int |
PLAY_WHEN_READY_CHANGE_REASON_AUDIO_BECOMING_NOISY |
Playback has been paused to avoid becoming noisy.
|
static int |
PLAY_WHEN_READY_CHANGE_REASON_AUDIO_FOCUS_LOSS |
Playback has been paused because of a loss of audio focus.
|
static int |
PLAY_WHEN_READY_CHANGE_REASON_END_OF_MEDIA_ITEM |
Playback has been paused at the end of a media item.
|
static int |
PLAY_WHEN_READY_CHANGE_REASON_REMOTE |
Playback has been started or paused because of a remote change.
|
static int |
PLAY_WHEN_READY_CHANGE_REASON_USER_REQUEST |
Playback has been started or paused by a call to
setPlayWhenReady(boolean) . |
static int |
PLAYBACK_SUPPRESSION_REASON_NONE |
Playback is not suppressed.
|
static int |
PLAYBACK_SUPPRESSION_REASON_TRANSIENT_AUDIO_FOCUS_LOSS |
Playback is suppressed due to transient audio focus loss.
|
static int |
REPEAT_MODE_ALL |
Repeats the entire timeline infinitely.
|
static int |
REPEAT_MODE_OFF |
Normal playback without repetition.
|
static int |
REPEAT_MODE_ONE |
Repeats the currently playing window infinitely during ongoing playback.
|
static int |
STATE_BUFFERING |
The player is not able to immediately play from its current position.
|
static int |
STATE_ENDED |
The player has finished playing the media.
|
static int |
STATE_IDLE |
The player does not have any media to play.
|
static int |
STATE_READY |
The player is able to immediately play from its current position.
|
static int |
TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED |
Timeline changed as a result of a change of the playlist items or the order of the items.
|
static int |
TIMELINE_CHANGE_REASON_SOURCE_UPDATE |
Timeline changed as a result of a dynamic update introduced by the played media.
|
Modifier and Type | Method | Description |
---|---|---|
void |
addListener(Player.EventListener listener) |
Register a listener to receive events from the player.
|
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.
|
void |
addMediaItems(int index,
List<MediaItem> mediaItems) |
Adds a list of media items at the given index of the playlist.
|
void |
addMediaItems(List<MediaItem> mediaItems) |
Adds a list of media items to the end of the playlist.
|
void |
clearMediaItems() |
Clears the playlist.
|
Looper |
getApplicationLooper() |
Returns the
Looper associated with the application thread that's used to access the
player and on which player events are received. |
Player.AudioComponent |
getAudioComponent() |
Returns the component of this player for audio output, or null if audio is not supported.
|
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 |
getBufferedPosition() |
Returns an estimate of the position in the current content window or ad up to which data is
buffered, in milliseconds.
|
long |
getContentBufferedPosition() |
If
isPlayingAd() returns true , returns an estimate of the content position in
the current content window up to which data is buffered, in milliseconds. |
long |
getContentDuration() |
If
isPlayingAd() returns true , returns the duration of the current content
window in milliseconds, or C.TIME_UNSET if the duration is not known. |
long |
getContentPosition() |
If
isPlayingAd() returns true , returns the content position that will be
played once all ads in the ad group have finished playing, in milliseconds. |
int |
getCurrentAdGroupIndex() |
If
isPlayingAd() returns true, returns the index of the ad group in the period
currently being played. |
int |
getCurrentAdIndexInAdGroup() |
If
isPlayingAd() returns true, returns the index of the ad in its ad group. |
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.
|
int |
getCurrentPeriodIndex() |
Returns the index of the period currently being played.
|
long |
getCurrentPosition() |
Returns the playback position in the current content window or ad, in milliseconds, or the
prospective position in milliseconds if the
current timeline is
empty. |
List<Metadata> |
getCurrentStaticMetadata() |
Returns the current static metadata for the track selections.
|
Object |
getCurrentTag() |
Deprecated.
Use
getCurrentMediaItem() and MediaItem.PlaybackProperties.tag
instead. |
Timeline |
getCurrentTimeline() |
Returns the current
Timeline . |
TrackGroupArray |
getCurrentTrackGroups() |
Returns the available track groups.
|
TrackSelectionArray |
getCurrentTrackSelections() |
Returns the current track selections for each renderer.
|
int |
getCurrentWindowIndex() |
Returns the index of the current
window in the timeline , or the prospective window index if the current timeline is empty. |
Player.DeviceComponent |
getDeviceComponent() |
Returns the component of this player for playback device, or null if it's not supported.
|
long |
getDuration() |
Returns the duration of the current content window or ad in milliseconds, or
C.TIME_UNSET if the duration is not known. |
MediaItem |
getMediaItemAt(int index) |
Returns the
MediaItem at the given index. |
int |
getMediaItemCount() |
Returns the number of
media items in the playlist. |
Player.MetadataComponent |
getMetadataComponent() |
Returns the component of this player for metadata output, or null if metadata is not supported.
|
int |
getNextWindowIndex() |
Returns the index of the window that will be played if
next() is called, which may
depend on the current repeat mode and whether shuffle mode is enabled. |
ExoPlaybackException |
getPlaybackError() |
Deprecated.
Use
getPlayerError() instead. |
PlaybackParameters |
getPlaybackParameters() |
Returns the currently active playback parameters.
|
int |
getPlaybackState() |
Returns the current
playback state of the player. |
int |
getPlaybackSuppressionReason() |
Returns the reason why playback is suppressed even though
getPlayWhenReady() is
true , or PLAYBACK_SUPPRESSION_REASON_NONE if playback is not suppressed. |
ExoPlaybackException |
getPlayerError() |
Returns the error that caused playback to fail.
|
boolean |
getPlayWhenReady() |
Whether playback will proceed when
getPlaybackState() == STATE_READY . |
int |
getPreviousWindowIndex() |
Returns the index of the window that will be played if
previous() is called, which may
depend on the current repeat mode and whether shuffle mode is enabled. |
int |
getRendererCount() |
Returns the number of renderers.
|
int |
getRendererType(int index) |
Returns the track type that the renderer at a given index handles.
|
int |
getRepeatMode() |
Returns the current
Player.RepeatMode used for playback. |
boolean |
getShuffleModeEnabled() |
Returns whether shuffling of windows is enabled.
|
Player.TextComponent |
getTextComponent() |
Returns the component of this player for text output, or null if text is not supported.
|
long |
getTotalBufferedDuration() |
Returns an estimate of the total buffered duration from the current position, in milliseconds.
|
Player.VideoComponent |
getVideoComponent() |
Returns the component of this player for video output, or null if video is not supported.
|
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 |
isLoading() |
Whether the player is currently loading the source.
|
boolean |
isPlaying() |
Returns whether the player is playing, i.e.
|
boolean |
isPlayingAd() |
Returns whether the player is currently playing an ad.
|
void |
moveMediaItem(int currentIndex,
int newIndex) |
Moves the media item at the current index to the new index.
|
void |
moveMediaItems(int fromIndex,
int toIndex,
int newIndex) |
Moves the media item range 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
getPlaybackState() == STATE_READY . |
void |
prepare() |
Prepares the player.
|
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 |
release() |
Releases the player.
|
void |
removeListener(Player.EventListener listener) |
Unregister a listener.
|
void |
removeMediaItem(int index) |
Removes the media item at the given index of the playlist.
|
void |
removeMediaItems(int fromIndex,
int toIndex) |
Removes a range of media items from the playlist.
|
void |
seekTo(int windowIndex,
long positionMs) |
Seeks to a position specified in milliseconds in the specified window.
|
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 |
setMediaItems(List<MediaItem> mediaItems,
boolean resetPosition) |
Clears the playlist and adds the specified
MediaItems . |
void |
setMediaItems(List<MediaItem> mediaItems,
int startWindowIndex,
long startPositionMs) |
Clears the playlist and adds the specified
MediaItems . |
void |
setPlaybackParameters(PlaybackParameters playbackParameters) |
Attempts to set the playback parameters.
|
void |
setPlayWhenReady(boolean playWhenReady) |
Sets whether playback should proceed when
getPlaybackState() == STATE_READY . |
void |
setRepeatMode(int repeatMode) |
Sets the
Player.RepeatMode to be used for playback. |
void |
setShuffleModeEnabled(boolean shuffleModeEnabled) |
Sets whether shuffling of windows is enabled.
|
void |
stop() |
Stops playback without resetting the player.
|
void |
stop(boolean reset) |
Deprecated.
|
static final int STATE_IDLE
static final int STATE_BUFFERING
static final int STATE_READY
getPlayWhenReady()
is true, and paused otherwise.static final int STATE_ENDED
static final int PLAY_WHEN_READY_CHANGE_REASON_USER_REQUEST
setPlayWhenReady(boolean)
.static final int PLAY_WHEN_READY_CHANGE_REASON_AUDIO_FOCUS_LOSS
static final int PLAY_WHEN_READY_CHANGE_REASON_AUDIO_BECOMING_NOISY
static final int PLAY_WHEN_READY_CHANGE_REASON_REMOTE
static final int PLAY_WHEN_READY_CHANGE_REASON_END_OF_MEDIA_ITEM
static final int PLAYBACK_SUPPRESSION_REASON_NONE
static final int PLAYBACK_SUPPRESSION_REASON_TRANSIENT_AUDIO_FOCUS_LOSS
static final int REPEAT_MODE_OFF
static final int REPEAT_MODE_ONE
REPEAT_MODE_OFF
, moving to the previous and next windows
respectively, and doing nothing when there is no previous or next window to move to.static final int REPEAT_MODE_ALL
REPEAT_MODE_OFF
, but with looping at the ends so that "Previous" when playing the
first window will move to the last window, and "Next" when playing the last window will move to
the first window.static final int DISCONTINUITY_REASON_PERIOD_TRANSITION
static final int DISCONTINUITY_REASON_SEEK
static final int DISCONTINUITY_REASON_SEEK_ADJUSTMENT
static final int DISCONTINUITY_REASON_AD_INSERTION
static final int DISCONTINUITY_REASON_INTERNAL
static final int TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED
static final int TIMELINE_CHANGE_REASON_SOURCE_UPDATE
static final int MEDIA_ITEM_TRANSITION_REASON_REPEAT
static final int MEDIA_ITEM_TRANSITION_REASON_AUTO
static final int MEDIA_ITEM_TRANSITION_REASON_SEEK
static final int MEDIA_ITEM_TRANSITION_REASON_PLAYLIST_CHANGED
static final int EVENT_TIMELINE_CHANGED
getCurrentTimeline()
changed.static final int EVENT_MEDIA_ITEM_TRANSITION
getCurrentMediaItem()
changed or the player started repeating the current item.static final int EVENT_TRACKS_CHANGED
getCurrentTrackGroups()
or getCurrentTrackSelections()
changed.static final int EVENT_STATIC_METADATA_CHANGED
getCurrentStaticMetadata()
changed.static final int EVENT_IS_LOADING_CHANGED
isLoading()
()} changed.static final int EVENT_PLAYBACK_STATE_CHANGED
getPlaybackState()
changed.static final int EVENT_PLAY_WHEN_READY_CHANGED
getPlayWhenReady()
changed.static final int EVENT_PLAYBACK_SUPPRESSION_REASON_CHANGED
getPlaybackSuppressionReason()
changed.static final int EVENT_IS_PLAYING_CHANGED
isPlaying()
changed.static final int EVENT_REPEAT_MODE_CHANGED
getRepeatMode()
changed.static final int EVENT_SHUFFLE_MODE_ENABLED_CHANGED
getShuffleModeEnabled()
changed.static final int EVENT_PLAYER_ERROR
getPlayerError()
changed.static final int EVENT_POSITION_DISCONTINUITY
Player.EventListener.onPositionDiscontinuity(int)
.static final int EVENT_PLAYBACK_PARAMETERS_CHANGED
getPlaybackParameters()
changed.@Nullable Player.AudioComponent getAudioComponent()
@Nullable Player.VideoComponent getVideoComponent()
@Nullable Player.TextComponent getTextComponent()
@Nullable Player.MetadataComponent getMetadataComponent()
@Nullable Player.DeviceComponent getDeviceComponent()
Looper getApplicationLooper()
Looper
associated with the application thread that's used to access the
player and on which player events are received.void addListener(Player.EventListener listener)
Looper
, then the listener will be called on the main thread.listener
- The listener to register.void removeListener(Player.EventListener listener)
listener
- The listener to unregister.void setMediaItems(List<MediaItem> mediaItems)
MediaItems
and resets the position to
the default position.mediaItems
- The new MediaItems
.void setMediaItems(List<MediaItem> mediaItems, boolean resetPosition)
MediaItems
.mediaItems
- The new MediaItems
.resetPosition
- Whether the playback position should be reset to the default position in
the first Timeline.Window
. If false, playback will start from the position defined
by getCurrentWindowIndex()
and getCurrentPosition()
.void setMediaItems(List<MediaItem> mediaItems, int startWindowIndex, long startPositionMs)
MediaItems
.mediaItems
- The new MediaItems
.startWindowIndex
- The window index to start playback from. If C.INDEX_UNSET
is
passed, the current position is not reset.startPositionMs
- The position in milliseconds to start playback from. If C.TIME_UNSET
is passed, the default position of the given window is used. In any case, if
startWindowIndex
is set to C.INDEX_UNSET
, this parameter is ignored and the
position is not reset at all.IllegalSeekPositionException
- If the provided windowIndex
is not within the
bounds of the list of media items.void setMediaItem(MediaItem mediaItem)
MediaItem
and resets the position to the
default position.mediaItem
- The new MediaItem
.void setMediaItem(MediaItem mediaItem, long startPositionMs)
MediaItem
.mediaItem
- The new MediaItem
.startPositionMs
- The position in milliseconds to start playback from.void setMediaItem(MediaItem mediaItem, boolean resetPosition)
MediaItem
.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 getCurrentWindowIndex()
and getCurrentPosition()
.void addMediaItem(MediaItem mediaItem)
mediaItem
- The MediaItem
to add.void addMediaItem(int index, MediaItem mediaItem)
index
- The index at which to add the item.mediaItem
- The MediaItem
to add.void addMediaItems(List<MediaItem> mediaItems)
mediaItems
- The MediaItems
to add.void addMediaItems(int index, List<MediaItem> mediaItems)
index
- The index at which to add the media items.mediaItems
- The MediaItems
to add.void moveMediaItem(int currentIndex, int newIndex)
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.void moveMediaItems(int fromIndex, int toIndex, int newIndex)
fromIndex
- The start of the range to move.toIndex
- The first item not to be included in the range (exclusive).newIndex
- The new index of the first media item of the range. If the new index is larger
than the size of the remaining playlist after removing the range, the range is moved to the
end of the playlist.void removeMediaItem(int index)
index
- The index at which to remove the media item.void removeMediaItems(int fromIndex, int toIndex)
fromIndex
- The index at which to start removing media items.toIndex
- The index of the first item to be kept (exclusive).void clearMediaItems()
void prepare()
@State int getPlaybackState()
playback state
of the player.playback state
.Player.EventListener.onPlaybackStateChanged(int)
@PlaybackSuppressionReason int getPlaybackSuppressionReason()
getPlayWhenReady()
is
true
, or PLAYBACK_SUPPRESSION_REASON_NONE
if playback is not suppressed.playback suppression reason
.Player.EventListener.onPlaybackSuppressionReasonChanged(int)
boolean isPlaying()
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
.
Player.EventListener.onIsPlayingChanged(boolean)
@Nullable ExoPlaybackException getPlayerError()
Player.EventListener.onPlayerError(ExoPlaybackException)
at the time of
failure. It can be queried using this method until the player is re-prepared.
Note that this method will always return null
if getPlaybackState()
is not
STATE_IDLE
.
null
.Player.EventListener.onPlayerError(ExoPlaybackException)
@Deprecated @Nullable ExoPlaybackException getPlaybackError()
getPlayerError()
instead.void play()
getPlaybackState()
== STATE_READY
. Equivalent to
setPlayWhenReady(true)
.void pause()
setPlayWhenReady(false)
.void setPlayWhenReady(boolean playWhenReady)
getPlaybackState()
== STATE_READY
.
If the player is already in the ready state then this method pauses and resumes playback.
playWhenReady
- Whether playback should proceed when ready.boolean getPlayWhenReady()
getPlaybackState()
== STATE_READY
.Player.EventListener.onPlayWhenReadyChanged(boolean, int)
void setRepeatMode(@RepeatMode int repeatMode)
Player.RepeatMode
to be used for playback.repeatMode
- The repeat mode.@RepeatMode int getRepeatMode()
Player.RepeatMode
used for playback.Player.EventListener.onRepeatModeChanged(int)
void setShuffleModeEnabled(boolean shuffleModeEnabled)
shuffleModeEnabled
- Whether shuffling is enabled.boolean getShuffleModeEnabled()
boolean isLoading()
Player.EventListener.onIsLoadingChanged(boolean)
void seekToDefaultPosition()
void seekToDefaultPosition(int windowIndex)
windowIndex
- The index of the window whose associated default position should be seeked
to.IllegalSeekPositionException
- If the player has a non-empty timeline and the provided
windowIndex
is not within the bounds of the current timeline.void seekTo(long positionMs)
positionMs
- The seek position in the current window, or C.TIME_UNSET
to seek to
the window's default position.void seekTo(int windowIndex, long positionMs)
windowIndex
- The index of the window.positionMs
- The seek position in the specified window, or C.TIME_UNSET
to seek to
the window's default position.IllegalSeekPositionException
- If the player has a non-empty timeline and the provided
windowIndex
is not within the bounds of the current timeline.boolean hasPrevious()
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.
void previous()
hasPrevious()
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.
boolean hasNext()
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.
void next()
hasNext()
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.
void setPlaybackParameters(@Nullable PlaybackParameters playbackParameters)
null
sets the parameters to the
default, PlaybackParameters.DEFAULT
, which means there is no speed or pitch adjustment.
Playback parameters changes may cause the player to buffer. Player.EventListener.onPlaybackParametersChanged(PlaybackParameters)
will be called whenever the
currently active playback parameters change.
playbackParameters
- The playback parameters, or null
to use the defaults.PlaybackParameters getPlaybackParameters()
void stop()
pause()
rather than this method if
the intention is to pause playback.
Calling this method will cause the playback state to transition to STATE_IDLE
. The
player instance can still be used, and 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.
@Deprecated void stop(boolean reset)
stop()
and clearMediaItems()
(if reset
is true) or
just stop()
(if reset
is false). Any player error will be cleared when
re-preparing
the player.void release()
int getRendererCount()
int getRendererType(int index)
For example, a video renderer will return C.TRACK_TYPE_VIDEO
, an audio renderer will
return C.TRACK_TYPE_AUDIO
and a text renderer will return C.TRACK_TYPE_TEXT
.
index
- The index of the renderer.TRACK_TYPE_*
constants defined in C
.TrackGroupArray getCurrentTrackGroups()
TrackSelectionArray getCurrentTrackSelections()
A concrete implementation may include null elements if it has a fixed number of renderer components, wishes to report a TrackSelection for each of them, and has one or more renderer components that is not assigned any selected tracks.
List<Metadata> getCurrentStaticMetadata()
The returned metadataList
is an immutable list of Metadata
instances, where
the elements correspond to the current track selections
,
or an empty list if there are no track selections or the selected tracks contain no static
metadata.
This metadata is considered static in that it comes from the tracks' declared Formats, rather than being timed (or dynamic) metadata, which is represented within a metadata track.
@Nullable Object getCurrentManifest()
Timeline getCurrentTimeline()
Timeline
. Never null, but may be empty.int getCurrentPeriodIndex()
int getCurrentWindowIndex()
window
in the timeline
, or the prospective window index if the current timeline
is empty.int getNextWindowIndex()
next()
is called, which may
depend on the current repeat mode and whether shuffle mode is enabled. Returns C.INDEX_UNSET
if hasNext()
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.
int getPreviousWindowIndex()
previous()
is called, which may
depend on the current repeat mode and whether shuffle mode is enabled. Returns C.INDEX_UNSET
if hasPrevious()
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.
@Deprecated @Nullable Object getCurrentTag()
getCurrentMediaItem()
and MediaItem.PlaybackProperties.tag
instead.@Nullable MediaItem getCurrentMediaItem()
int getMediaItemCount()
media items
in the playlist.long getDuration()
C.TIME_UNSET
if the duration is not known.long getCurrentPosition()
current timeline
is
empty.long getBufferedPosition()
int getBufferedPercentage()
long getTotalBufferedDuration()
boolean isCurrentWindowDynamic()
false
if the Timeline
is
empty.Timeline.Window.isDynamic
boolean isCurrentWindowLive()
false
if the Timeline
is empty.Timeline.Window.isLive()
long getCurrentLiveOffset()
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.
boolean isCurrentWindowSeekable()
false
if the Timeline
is
empty.Timeline.Window.isSeekable
boolean isPlayingAd()
int getCurrentAdGroupIndex()
isPlayingAd()
returns true, returns the index of the ad group in the period
currently being played. Returns C.INDEX_UNSET
otherwise.int getCurrentAdIndexInAdGroup()
isPlayingAd()
returns true, returns the index of the ad in its ad group. Returns
C.INDEX_UNSET
otherwise.long getContentDuration()
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 getDuration()
.long getContentPosition()
isPlayingAd()
returns true
, returns the content position that will be
played once all ads in the ad group have finished playing, in milliseconds. If there is no ad
playing, the returned position is the same as that returned by getCurrentPosition()
.long getContentBufferedPosition()
isPlayingAd()
returns true
, returns an estimate of the content position in
the current content window up to which data is buffered, in milliseconds. If there is no ad
playing, the returned position is the same as that returned by getBufferedPosition()
.