| Modifier and Type | Class and Description |
|---|---|
static interface |
SimpleExoPlayer.VideoListener
A listener for video rendering information from a
SimpleExoPlayer. |
ExoPlayer.EventListener, ExoPlayer.ExoPlayerComponent, ExoPlayer.ExoPlayerMessagePlayer.RepeatMode| Modifier and Type | Field and Description |
|---|---|
protected Renderer[] |
renderers |
REPEAT_MODE_ALL, REPEAT_MODE_OFF, REPEAT_MODE_ONE, STATE_BUFFERING, STATE_ENDED, STATE_IDLE, STATE_READY| Modifier | Constructor and Description |
|---|---|
protected |
SimpleExoPlayer(RenderersFactory renderersFactory,
TrackSelector trackSelector,
LoadControl loadControl) |
| Modifier and Type | Method and Description |
|---|---|
void |
addListener(Player.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 |
clearMetadataOutput(MetadataRenderer.Output output)
Clears the output receiving metadata events if it matches the one passed.
|
void |
clearTextOutput(TextRenderer.Output output)
Clears the output receiving text events if it matches the one passed.
|
void |
clearVideoListener(SimpleExoPlayer.VideoListener listener)
Clears the listener receiving video events if it matches the one passed.
|
void |
clearVideoSurface()
|
void |
clearVideoSurface(Surface surface)
Clears the
Surface onto which video is being rendered if it matches the one passed. |
void |
clearVideoSurfaceHolder(SurfaceHolder surfaceHolder)
Clears the
SurfaceHolder that holds the Surface onto which video is being
rendered if it matches the one passed. |
void |
clearVideoSurfaceView(SurfaceView surfaceView)
Clears the
SurfaceView onto which video is being rendered if it matches the one passed. |
void |
clearVideoTextureView(TextureView textureView)
Clears the
TextureView onto which video is being rendered if it matches the one passed. |
AudioAttributes |
getAudioAttributes()
Returns the attributes for audio playback.
|
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
C.AUDIO_SESSION_ID_UNSET if not set. |
int |
getAudioStreamType()
Deprecated.
Use
getAudioAttributes(). |
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
Player.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
Player.isPlayingAd() returns true, returns the index of the ad group in the period
currently being played. |
int |
getCurrentAdIndexInAdGroup()
If
Player.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. |
Looper |
getPlaybackLooper()
Gets the
Looper associated with the playback thread. |
PlaybackParameters |
getPlaybackParameters()
Returns the currently active playback parameters.
|
int |
getPlaybackState()
Returns the current state of the player.
|
boolean |
getPlayWhenReady()
Whether playback will proceed when
Player.getPlaybackState() == Player.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. |
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.
|
int |
getVideoScalingMode()
Returns the video scaling mode.
|
float |
getVolume()
Returns the audio volume, with 0 being silence and 1 being unity gain.
|
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 |
prepare(MediaSource mediaSource)
Prepares the player to play the provided
MediaSource. |
void |
prepare(MediaSource mediaSource,
boolean resetPosition,
boolean resetState)
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(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 |
sendMessages(ExoPlayer.ExoPlayerMessage... messages)
Sends messages to their target components.
|
void |
setAudioAttributes(AudioAttributes audioAttributes)
Sets the attributes for audio playback, used by the underlying audio track.
|
void |
setAudioDebugListener(AudioRendererEventListener listener)
Sets a listener to receive debug events from the audio renderer.
|
void |
setAudioStreamType(int streamType)
Deprecated.
|
void |
setMetadataOutput(MetadataRenderer.Output output)
Sets a listener to receive metadata events.
|
void |
setPlaybackParameters(PlaybackParameters playbackParameters)
Attempts to set the playback parameters.
|
void |
setPlaybackParams(PlaybackParams params)
Deprecated.
|
void |
setPlayWhenReady(boolean playWhenReady)
Sets whether playback should proceed when
Player.getPlaybackState() == Player.STATE_READY. |
void |
setRepeatMode(int repeatMode)
Sets the
Player.RepeatMode to be used for playback. |
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 |
setVideoScalingMode(int videoScalingMode)
Sets the video scaling mode.
|
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 audioVolume)
Sets the audio volume, with 0 being silence and 1 being unity gain.
|
void |
stop()
Stops playback.
|
protected final Renderer[] renderers
protected SimpleExoPlayer(RenderersFactory renderersFactory, TrackSelector trackSelector, LoadControl loadControl)
public void setVideoScalingMode(int videoScalingMode)
Note that the scaling mode only applies if a MediaCodec-based video Renderer is
enabled and if the output surface is owned by a SurfaceView.
videoScalingMode - The video scaling mode.public int getVideoScalingMode()
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 clearVideoSurface(Surface surface)
Surface onto which video is being rendered if it matches the one passed.
Else does nothing.surface - The surface to clear.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 clearVideoSurfaceHolder(SurfaceHolder surfaceHolder)
SurfaceHolder that holds the Surface onto which video is being
rendered if it matches the one passed. Else does nothing.surfaceHolder - The surface holder to clear.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 clearVideoSurfaceView(SurfaceView surfaceView)
SurfaceView onto which video is being rendered if it matches the one passed.
Else does nothing.surfaceView - The texture view to clear.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 clearVideoTextureView(TextureView textureView)
TextureView onto which video is being rendered if it matches the one passed.
Else does nothing.textureView - The texture view to clear.@Deprecated public void setAudioStreamType(int streamType)
setAudioAttributes(AudioAttributes).Setting the stream type during playback may introduce a short gap in audio output as the audio track is recreated. A new audio session id will also be generated.
Calling this method overwrites any attributes set previously by calling
setAudioAttributes(AudioAttributes).
streamType - The stream type for audio playback.@Deprecated public int getAudioStreamType()
getAudioAttributes().public void setAudioAttributes(AudioAttributes audioAttributes)
Setting the audio attributes during playback may introduce a short gap in audio output as the audio track is recreated. A new audio session id will also be generated.
If tunneling is enabled by the track selector, the specified audio attributes will be ignored, but they will take effect if audio is later played without tunneling.
If the device is running a build before platform API version 21, audio attributes cannot be set
directly on the underlying audio track. In this case, the usage will be mapped onto an
equivalent stream type using Util.getStreamTypeForAudioUsage(int).
audioAttributes - The attributes to use for audio playback.public AudioAttributes getAudioAttributes()
public void setVolume(float audioVolume)
audioVolume - The audio volume.public float getVolume()
@Deprecated public void setPlaybackParams(@Nullable PlaybackParams params)
setPlaybackParameters(PlaybackParameters).PlaybackParams governing audio playback.params - The PlaybackParams, or null to clear any previously set parameters.public Format getVideoFormat()
public Format getAudioFormat()
public int getAudioSessionId()
C.AUDIO_SESSION_ID_UNSET 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 clearVideoListener(SimpleExoPlayer.VideoListener listener)
listener - The listener to clear.public void setTextOutput(TextRenderer.Output output)
output - The output.public void clearTextOutput(TextRenderer.Output output)
output - The output to clear.public void setMetadataOutput(MetadataRenderer.Output output)
output - The output.public void clearMetadataOutput(MetadataRenderer.Output output)
output - The output to clear.public void setVideoDebugListener(VideoRendererEventListener listener)
listener - The listener.public void setAudioDebugListener(AudioRendererEventListener listener)
listener - The listener.public Looper getPlaybackLooper()
ExoPlayerLooper associated with the playback thread.getPlaybackLooper in interface ExoPlayerLooper associated with the playback thread.public void addListener(Player.EventListener listener)
PlayerLooper, then the listener will be called on the main thread.addListener in interface Playerlistener - The listener to register.public void removeListener(Player.EventListener listener)
PlayerremoveListener in interface Playerlistener - The listener to unregister.public int getPlaybackState()
PlayergetPlaybackState in interface PlayerSTATE constants defined in this interface.public void prepare(MediaSource mediaSource)
ExoPlayerMediaSource. Equivalent to
prepare(mediaSource, true, true).public void prepare(MediaSource mediaSource, boolean resetPosition, boolean resetState)
ExoPlayerMediaSource, optionally resetting the playback
position the default position in the first Timeline.Window.prepare in interface ExoPlayermediaSource - 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 Player.getCurrentWindowIndex() and Player.getCurrentPosition().resetState - Whether the timeline, manifest, tracks and track selections 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)
PlayerPlayer.getPlaybackState() == Player.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 PlayerplayWhenReady - Whether playback should proceed when ready.public boolean getPlayWhenReady()
PlayerPlayer.getPlaybackState() == Player.STATE_READY.getPlayWhenReady in interface Playerpublic int getRepeatMode()
PlayerPlayer.RepeatMode used for playback.getRepeatMode in interface Playerpublic void setRepeatMode(int repeatMode)
PlayerPlayer.RepeatMode to be used for playback.setRepeatMode in interface PlayerrepeatMode - A repeat mode.public boolean isLoading()
Playerpublic void seekToDefaultPosition()
PlayerseekToDefaultPosition in interface Playerpublic void seekToDefaultPosition(int windowIndex)
PlayerseekToDefaultPosition in interface PlayerwindowIndex - The index of the window whose associated default position should be seeked
to.public void seekTo(long positionMs)
PlayerseekTo in interface PlayerpositionMs - The seek position in the current window, or C.TIME_UNSET to seek to
the window's default position.public void seekTo(int windowIndex,
long positionMs)
PlayerseekTo in interface PlayerwindowIndex - 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.public void setPlaybackParameters(PlaybackParameters playbackParameters)
Playernull 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.
setPlaybackParameters in interface PlayerplaybackParameters - The playback parameters, or null to use the defaults.public PlaybackParameters getPlaybackParameters()
PlayergetPlaybackParameters in interface PlayerPlayer.EventListener.onPlaybackParametersChanged(PlaybackParameters)public void stop()
PlayersetPlayWhenReady(false) 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 reset the playback position.
public void release()
Playerpublic void sendMessages(ExoPlayer.ExoPlayerMessage... messages)
ExoPlayerExoPlaybackException then it is propagated out of the player
as an error.sendMessages in interface ExoPlayermessages - The messages to be sent.public void blockingSendMessages(ExoPlayer.ExoPlayerMessage... messages)
ExoPlayerExoPlayer.sendMessages(ExoPlayerMessage...) that blocks until after the messages have
been delivered.blockingSendMessages in interface ExoPlayermessages - The messages to be sent.public int getRendererCount()
PlayergetRendererCount in interface Playerpublic int getRendererType(int index)
PlayergetRendererType in interface Playerindex - The index of the renderer.TRACK_TYPE_* constants defined in C.Renderer.getTrackType()public TrackGroupArray getCurrentTrackGroups()
PlayergetCurrentTrackGroups in interface Playerpublic TrackSelectionArray getCurrentTrackSelections()
PlayergetCurrentTrackSelections in interface Playerpublic Timeline getCurrentTimeline()
PlayerTimeline. Never null, but may be empty.getCurrentTimeline in interface Playerpublic Object getCurrentManifest()
PlayergetCurrentManifest in interface Playerpublic int getCurrentPeriodIndex()
PlayergetCurrentPeriodIndex in interface Playerpublic int getCurrentWindowIndex()
PlayergetCurrentWindowIndex in interface Playerpublic long getDuration()
PlayerC.TIME_UNSET if the
duration is not known.getDuration in interface Playerpublic long getCurrentPosition()
PlayergetCurrentPosition in interface Playerpublic long getBufferedPosition()
PlayergetBufferedPosition in interface Playerpublic int getBufferedPercentage()
PlayergetBufferedPercentage in interface Playerpublic boolean isCurrentWindowDynamic()
Playerfalse if the Timeline is
empty.isCurrentWindowDynamic in interface PlayerTimeline.Window.isDynamicpublic boolean isCurrentWindowSeekable()
Playerfalse if the Timeline is
empty.isCurrentWindowSeekable in interface PlayerTimeline.Window.isSeekablepublic boolean isPlayingAd()
PlayerisPlayingAd in interface Playerpublic int getCurrentAdGroupIndex()
PlayerPlayer.isPlayingAd() returns true, returns the index of the ad group in the period
currently being played. Returns C.INDEX_UNSET otherwise.getCurrentAdGroupIndex in interface Playerpublic int getCurrentAdIndexInAdGroup()
PlayerPlayer.isPlayingAd() returns true, returns the index of the ad in its ad group. Returns
C.INDEX_UNSET otherwise.getCurrentAdIndexInAdGroup in interface Playerpublic long getContentPosition()
PlayerPlayer.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 Player.getCurrentPosition().getContentPosition in interface Player