Modifier and Type | Class and Description |
---|---|
static interface |
SimpleExoPlayer.VideoListener
A listener for video rendering information from a
SimpleExoPlayer . |
ExoPlayer.EventListener, ExoPlayer.ExoPlayerComponent, ExoPlayer.ExoPlayerMessage
STATE_BUFFERING, STATE_ENDED, STATE_IDLE, STATE_READY
Modifier and Type | Method and Description |
---|---|
void |
addListener(ExoPlayer.EventListener listener)
Register a listener to receive events from the player.
|
void |
blockingSendMessages(ExoPlayer.ExoPlayerMessage... messages)
Variant of
ExoPlayer.sendMessages(ExoPlayerMessage...) that blocks until after the messages have
been delivered. |
void |
clearVideoSurface()
|
DecoderCounters |
getAudioDecoderCounters()
Returns
DecoderCounters for audio, or null if no audio is being played. |
Format |
getAudioFormat()
Returns the audio format currently being played, or null if no audio is being played.
|
int |
getAudioSessionId()
Returns the audio session identifier, or
AudioTrack.SESSION_ID_NOT_SET if not set. |
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.
|
Object |
getCurrentManifest()
Returns the current manifest.
|
int |
getCurrentPeriodIndex()
Returns the index of the period currently being played, or
C.INDEX_UNSET if unknown. |
long |
getCurrentPosition()
Returns the playback position in the current window, in milliseconds.
|
Timeline |
getCurrentTimeline()
Returns the current
Timeline , or null if there is no timeline. |
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. |
PlaybackParams |
getPlaybackParams()
Returns the
PlaybackParams governing audio playback, or null if not set. |
int |
getPlaybackState()
Returns the current state of the player.
|
boolean |
getPlayWhenReady()
Whether playback will proceed when
ExoPlayer.getPlaybackState() == ExoPlayer.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.
|
DecoderCounters |
getVideoDecoderCounters()
Returns
DecoderCounters for video, or null if no video is being played. |
Format |
getVideoFormat()
Returns the video format currently being played, or null if no video is being played.
|
float |
getVolume()
Returns the audio volume, with 0 being silence and 1 being unity gain.
|
boolean |
isLoading()
Whether the player is currently loading the source.
|
void |
prepare(MediaSource mediaSource)
Prepares the player to play the provided
MediaSource . |
void |
prepare(MediaSource mediaSource,
boolean resetPosition,
boolean resetTimeline)
Prepares the player to play the provided
MediaSource , optionally resetting the playback
position the default position in the first Timeline.Window . |
void |
release()
Releases the player.
|
void |
removeListener(ExoPlayer.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 |
sendMessages(ExoPlayer.ExoPlayerMessage... messages)
Sends messages to their target components.
|
void |
setAudioDebugListener(AudioRendererEventListener listener)
Sets a listener to receive debug events from the audio renderer.
|
void |
setId3Output(MetadataRenderer.Output<List<Id3Frame>> output)
Sets a listener to receive ID3 metadata events.
|
void |
setPlaybackParams(PlaybackParams params)
Sets the
PlaybackParams governing audio playback. |
void |
setPlayWhenReady(boolean playWhenReady)
Sets whether playback should proceed when
ExoPlayer.getPlaybackState() == ExoPlayer.STATE_READY . |
void |
setTextOutput(TextRenderer.Output output)
Sets an output to receive text events.
|
void |
setVideoDebugListener(VideoRendererEventListener listener)
Sets a listener to receive debug events from the video renderer.
|
void |
setVideoListener(SimpleExoPlayer.VideoListener listener)
Sets a listener to receive video events.
|
void |
setVideoSurface(Surface surface)
Sets the
Surface onto which video will be rendered. |
void |
setVideoSurfaceHolder(SurfaceHolder surfaceHolder)
Sets the
SurfaceHolder that holds the Surface onto which video will be
rendered. |
void |
setVideoSurfaceView(SurfaceView surfaceView)
Sets the
SurfaceView onto which video will be rendered. |
void |
setVideoTextureView(TextureView textureView)
Sets the
TextureView onto which video will be rendered. |
void |
setVolume(float volume)
Sets the audio volume, with 0 being silence and 1 being unity gain.
|
void |
stop()
Stops playback.
|
public int getRendererCount()
public int getRendererType(int index)
index
- The index of the renderer.TRACK_TYPE_*
constants defined in C
.Renderer.getTrackType()
public void clearVideoSurface()
public void setVideoSurface(Surface surface)
Surface
onto which video will be rendered. The caller is responsible for
tracking the lifecycle of the surface, and must clear the surface by calling
setVideoSurface(null)
if the surface is destroyed.
If the surface is held by a SurfaceView
, TextureView
or SurfaceHolder
then it's recommended to use setVideoSurfaceView(SurfaceView)
,
setVideoTextureView(TextureView)
or setVideoSurfaceHolder(SurfaceHolder)
rather than this method, since passing the holder allows the player to track the lifecycle of
the surface automatically.
surface
- The Surface
.public void setVideoSurfaceHolder(SurfaceHolder surfaceHolder)
SurfaceHolder
that holds the Surface
onto which video will be
rendered. The player will track the lifecycle of the surface automatically.surfaceHolder
- The surface holder.public void setVideoSurfaceView(SurfaceView surfaceView)
SurfaceView
onto which video will be rendered. The player will track the
lifecycle of the surface automatically.surfaceView
- The surface view.public void setVideoTextureView(TextureView textureView)
TextureView
onto which video will be rendered. The player will track the
lifecycle of the surface automatically.textureView
- The texture view.public void setVolume(float volume)
volume
- The volume.public float getVolume()
public void setPlaybackParams(PlaybackParams params)
PlaybackParams
governing audio playback.params
- The PlaybackParams
, or null to clear any previously set parameters.public PlaybackParams getPlaybackParams()
PlaybackParams
governing audio playback, or null if not set.public Format getVideoFormat()
public Format getAudioFormat()
public int getAudioSessionId()
AudioTrack.SESSION_ID_NOT_SET
if not set.public DecoderCounters getVideoDecoderCounters()
DecoderCounters
for video, or null if no video is being played.public DecoderCounters getAudioDecoderCounters()
DecoderCounters
for audio, or null if no audio is being played.public void setVideoListener(SimpleExoPlayer.VideoListener listener)
listener
- The listener.public void setVideoDebugListener(VideoRendererEventListener listener)
listener
- The listener.public void setAudioDebugListener(AudioRendererEventListener listener)
listener
- The listener.public void setTextOutput(TextRenderer.Output output)
output
- The output.public void setId3Output(MetadataRenderer.Output<List<Id3Frame>> output)
output
- The output.public void addListener(ExoPlayer.EventListener listener)
ExoPlayer
addListener
in interface ExoPlayer
listener
- The listener to register.public void removeListener(ExoPlayer.EventListener listener)
ExoPlayer
removeListener
in interface ExoPlayer
listener
- The listener to unregister.public int getPlaybackState()
ExoPlayer
getPlaybackState
in interface ExoPlayer
STATE
constants defined in this interface.public void prepare(MediaSource mediaSource)
ExoPlayer
MediaSource
. Equivalent to
prepare(mediaSource, true, true)
.public void prepare(MediaSource mediaSource, boolean resetPosition, boolean resetTimeline)
ExoPlayer
MediaSource
, optionally resetting the playback
position the default position in the first Timeline.Window
.prepare
in interface ExoPlayer
mediaSource
- The MediaSource
to play.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 ExoPlayer.getCurrentWindowIndex()
and ExoPlayer.getCurrentPosition()
.resetTimeline
- Whether the timeline and manifest should be reset. Should be true unless
the player is being prepared to play the same media as it was playing previously (e.g. if
playback failed and is being retried).public void setPlayWhenReady(boolean playWhenReady)
ExoPlayer
ExoPlayer.getPlaybackState()
== ExoPlayer.STATE_READY
.
If the player is already in the ready state then this method can be used to pause and resume playback.
setPlayWhenReady
in interface ExoPlayer
playWhenReady
- Whether playback should proceed when ready.public boolean getPlayWhenReady()
ExoPlayer
ExoPlayer.getPlaybackState()
== ExoPlayer.STATE_READY
.getPlayWhenReady
in interface ExoPlayer
public boolean isLoading()
ExoPlayer
public void seekToDefaultPosition()
ExoPlayer
ExoPlayer.prepare(MediaSource)
. For live streams it will typically
be the live edge of the window. For other streams it will typically be the start of the window.seekToDefaultPosition
in interface ExoPlayer
public void seekToDefaultPosition(int windowIndex)
ExoPlayer
ExoPlayer.prepare(MediaSource)
. For live streams it will typically
be the live edge of the window. For other streams it will typically be the start of the window.seekToDefaultPosition
in interface ExoPlayer
windowIndex
- The index of the window whose associated default position should be seeked
to.public void seekTo(long positionMs)
ExoPlayer
public void seekTo(int windowIndex, long positionMs)
ExoPlayer
public void stop()
ExoPlayer
setPlayWhenReady(false)
rather than this method if the intention
is to pause playback.
Calling this method will cause the playback state to transition to ExoPlayer.STATE_IDLE
. The
player instance can still be used, and ExoPlayer.release()
must still be called on the player if
it's no longer required.
Calling this method does not reset the playback position.
public void release()
ExoPlayer
public void sendMessages(ExoPlayer.ExoPlayerMessage... messages)
ExoPlayer
ExoPlaybackException
then it is propagated out of the player
as an error.sendMessages
in interface ExoPlayer
messages
- The messages to be sent.public void blockingSendMessages(ExoPlayer.ExoPlayerMessage... messages)
ExoPlayer
ExoPlayer.sendMessages(ExoPlayerMessage...)
that blocks until after the messages have
been delivered.blockingSendMessages
in interface ExoPlayer
messages
- The messages to be sent.public int getCurrentPeriodIndex()
ExoPlayer
C.INDEX_UNSET
if unknown.getCurrentPeriodIndex
in interface ExoPlayer
public int getCurrentWindowIndex()
ExoPlayer
getCurrentWindowIndex
in interface ExoPlayer
public long getDuration()
ExoPlayer
C.TIME_UNSET
if the
duration is not known.getDuration
in interface ExoPlayer
public long getCurrentPosition()
ExoPlayer
getCurrentPosition
in interface ExoPlayer
public long getBufferedPosition()
ExoPlayer
getBufferedPosition
in interface ExoPlayer
public int getBufferedPercentage()
ExoPlayer
getBufferedPercentage
in interface ExoPlayer
public Timeline getCurrentTimeline()
ExoPlayer
Timeline
, or null
if there is no timeline.getCurrentTimeline
in interface ExoPlayer
public Object getCurrentManifest()
ExoPlayer
MediaSource
passed to
ExoPlayer.prepare(com.google.android.exoplayer2.source.MediaSource)
.getCurrentManifest
in interface ExoPlayer