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 and 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.DiscontinuityReason
Reasons for position discontinuities.
|
static interface |
Player.EventListener
Listener of changes in player state.
|
static interface |
Player.MetadataComponent
The metadata component of a
Player . |
static interface |
Player.RepeatMode
Repeat modes for playback.
|
static interface |
Player.TextComponent
The text component of a
Player . |
static interface |
Player.TimelineChangeReason
Reasons for timeline and/or manifest changes.
|
static interface |
Player.VideoComponent
The video component of a
Player . |
Modifier and Type | Field and 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 |
REPEAT_MODE_ALL
"Repeat All" mode to repeat the entire timeline infinitely.
|
static int |
REPEAT_MODE_OFF
Normal playback without repetition.
|
static int |
REPEAT_MODE_ONE
"Repeat One" mode to repeat the currently playing window infinitely.
|
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_DYNAMIC
Timeline or manifest changed as a result of an dynamic update introduced by the played media.
|
static int |
TIMELINE_CHANGE_REASON_PREPARED
Timeline and manifest changed as a result of a player initialization with new media.
|
static int |
TIMELINE_CHANGE_REASON_RESET
Timeline and manifest changed as a result of a player reset.
|
Modifier and Type | Method and Description |
---|---|
void |
addListener(Player.EventListener listener)
Register a listener to receive events from the player.
|
android.os.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. |
java.lang.Object |
getCurrentManifest()
Returns the current manifest.
|
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.
|
java.lang.Object |
getCurrentTag()
Returns the tag of the currently playing window in the timeline.
|
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 window currently being played.
|
long |
getDuration()
Returns the duration of the current content window or ad in milliseconds, or
C.TIME_UNSET if the duration is not known. |
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 next timeline window to be played, which may depend on the current
repeat mode and whether shuffle mode is enabled.
|
ExoPlaybackException |
getPlaybackError()
Returns the error that caused playback to fail.
|
PlaybackParameters |
getPlaybackParameters()
Returns the currently active playback parameters.
|
int |
getPlaybackState()
Returns the current state of the player.
|
boolean |
getPlayWhenReady()
Whether playback will proceed when
getPlaybackState() == STATE_READY . |
int |
getPreviousWindowIndex()
Returns the index of the previous timeline window to be played, 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 |
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 |
isPlayingAd()
Returns whether the player is currently playing an ad.
|
void |
next()
Seeks to the default position of the next window in the timeline, which may depend on the
current repeat mode and whether shuffle mode is enabled.
|
void |
previous()
Seeks to the default position of the previous window in the timeline, 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 |
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 |
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)
Stops playback and optionally resets the player.
|
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 REPEAT_MODE_OFF
static final int REPEAT_MODE_ONE
static final int REPEAT_MODE_ALL
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_PREPARED
static final int TIMELINE_CHANGE_REASON_RESET
static final int TIMELINE_CHANGE_REASON_DYNAMIC
@Nullable Player.AudioComponent getAudioComponent()
@Nullable Player.VideoComponent getVideoComponent()
@Nullable Player.TextComponent getTextComponent()
@Nullable Player.MetadataComponent getMetadataComponent()
android.os.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.int getPlaybackState()
STATE
constants defined in this interface.@Nullable ExoPlaybackException getPlaybackError()
Player.EventListener.onPlayerError(ExoPlaybackException)
at the time of
failure. It can be queried using this method until stop(true)
is called or the player
is re-prepared.null
.void setPlayWhenReady(boolean playWhenReady)
getPlaybackState()
== STATE_READY
.
If the player is already in the ready state then this method can be used to pause and resume playback.
playWhenReady
- Whether playback should proceed when ready.boolean getPlayWhenReady()
getPlaybackState()
== STATE_READY
.void setRepeatMode(@Player.RepeatMode int repeatMode)
Player.RepeatMode
to be used for playback.repeatMode
- A repeat mode.@Player.RepeatMode int getRepeatMode()
Player.RepeatMode
used for playback.void setShuffleModeEnabled(boolean shuffleModeEnabled)
shuffleModeEnabled
- Whether shuffling is enabled.boolean getShuffleModeEnabled()
boolean isLoading()
void seekToDefaultPosition()
void seekToDefaultPosition(int windowIndex)
windowIndex
- The index of the window whose associated default position should be seeked
to.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()
void previous()
hasPrevious()
is false
.boolean hasNext()
void next()
hasNext()
is
false
.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. When that listener is called, the parameters
passed to it may not match playbackParameters
. For example, the chosen speed or pitch
may be out of range, in which case they are constrained to a set of permitted values. If it is
not possible to change the playback parameters, the listener will not be invoked.
playbackParameters
- The playback parameters, or null
to use the defaults.PlaybackParameters getPlaybackParameters()
void stop()
setPlayWhenReady(false)
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 reset the playback position.
void stop(boolean reset)
setPlayWhenReady(false)
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.
reset
- Whether the player should be reset.void release()
int getRendererCount()
int getRendererType(int index)
index
- The index of the renderer.TRACK_TYPE_*
constants defined in C
.Renderer.getTrackType()
TrackGroupArray getCurrentTrackGroups()
TrackSelectionArray getCurrentTrackSelections()
@Nullable java.lang.Object getCurrentManifest()
Timeline getCurrentTimeline()
Timeline
. Never null, but may be empty.int getCurrentPeriodIndex()
int getCurrentWindowIndex()
int getNextWindowIndex()
C.INDEX_UNSET
if the window
currently being played is the last window.int getPreviousWindowIndex()
C.INDEX_UNSET
if the window
currently being played is the first window.@Nullable java.lang.Object getCurrentTag()
long getDuration()
C.TIME_UNSET
if the duration is not known.long getCurrentPosition()
long getBufferedPosition()
int getBufferedPercentage()
long getTotalBufferedDuration()
boolean isCurrentWindowDynamic()
false
if the Timeline
is
empty.Timeline.Window.isDynamic
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()
.