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.EventListener
Listener of changes in player state.
|
static interface |
Player.RepeatMode
Repeat modes for playback.
|
| Modifier and Type | Field and Description |
|---|---|
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.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addListener(Player.EventListener listener)
Register a listener to receive events from the player.
|
int |
getBufferedPercentage()
Returns an estimate of the percentage in the current window up to which data is buffered, or 0
if no estimate is available.
|
long |
getBufferedPosition()
Returns an estimate of the position in the current window up to which data is buffered, in
milliseconds.
|
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. |
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 window, in milliseconds.
|
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 window in milliseconds, or
C.TIME_UNSET if the
duration is not known. |
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 |
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 |
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 |
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 |
stop()
Stops playback.
|
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
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.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(int repeatMode)
Player.RepeatMode to be used for playback.repeatMode - A repeat mode.int getRepeatMode()
Player.RepeatMode used for playback.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.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 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 Object getCurrentManifest()
Timeline getCurrentTimeline()
Timeline. Never null, but may be empty.int getCurrentPeriodIndex()
int getCurrentWindowIndex()
long getDuration()
C.TIME_UNSET if the
duration is not known.long getCurrentPosition()
long getBufferedPosition()
int getBufferedPercentage()
boolean isCurrentWindowDynamic()
false if the Timeline is
empty.Timeline.Window.isDynamicboolean isCurrentWindowSeekable()
false if the Timeline is
empty.Timeline.Window.isSeekableboolean 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 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().