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
Player.DefaultEventListener, Player.DiscontinuityReason, Player.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
DISCONTINUITY_REASON_INTERNAL, DISCONTINUITY_REASON_PERIOD_TRANSITION, DISCONTINUITY_REASON_SEEK, DISCONTINUITY_REASON_SEEK_ADJUSTMENT
Modifier | Constructor and Description |
---|---|
protected |
SimpleExoPlayer(RenderersFactory renderersFactory,
TrackSelector trackSelector,
LoadControl loadControl) |
Modifier and Type | Method and Description |
---|---|
void |
addAudioDebugListener(AudioRendererEventListener listener)
Adds a listener to receive debug events from the audio renderer.
|
void |
addListener(Player.EventListener listener)
Register a listener to receive events from the player.
|
void |
addMetadataOutput(MetadataOutput listener)
Registers an output to receive metadata events.
|
void |
addTextOutput(TextOutput listener)
Registers an output to receive text events.
|
void |
addVideoDebugListener(VideoRendererEventListener listener)
Adds a listener to receive debug events from the video renderer.
|
void |
addVideoListener(SimpleExoPlayer.VideoListener listener)
Adds a listener to receive video events.
|
void |
blockingSendMessages(ExoPlayer.ExoPlayerMessage... messages)
Variant of
ExoPlayer.sendMessages(ExoPlayerMessage...) that blocks until after the messages have
been delivered. |
void |
clearMetadataOutput(MetadataOutput output)
Deprecated.
|
void |
clearTextOutput(TextOutput output)
Deprecated.
|
void |
clearVideoListener(SimpleExoPlayer.VideoListener listener)
Deprecated.
|
void |
clearVideoSurface()
Clears any
Surface , SurfaceHolder , SurfaceView or TextureView
currently set on the player. |
void |
clearVideoSurface(android.view.Surface surface)
Clears the
Surface onto which video is being rendered if it matches the one passed. |
void |
clearVideoSurfaceHolder(android.view.SurfaceHolder surfaceHolder)
Clears the
SurfaceHolder that holds the Surface onto which video is being
rendered if it matches the one passed. |
void |
clearVideoSurfaceView(android.view.SurfaceView surfaceView)
Clears the
SurfaceView onto which video is being rendered if it matches the one passed. |
void |
clearVideoTextureView(android.view.TextureView textureView)
Clears the
TextureView onto which video is being rendered if it matches the one passed. |
protected ExoPlayer |
createExoPlayerImpl(Renderer[] renderers,
TrackSelector trackSelector,
LoadControl loadControl)
Creates the
ExoPlayer implementation used by this instance. |
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. |
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 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. |
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.
|
android.os.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 |
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.
|
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 |
removeAudioDebugListener(AudioRendererEventListener listener)
Removes a listener to receive debug events from the audio renderer.
|
void |
removeListener(Player.EventListener listener)
Unregister a listener.
|
void |
removeMetadataOutput(MetadataOutput listener)
Removes a metadata output.
|
void |
removeTextOutput(TextOutput listener)
Removes a text output.
|
void |
removeVideoDebugListener(VideoRendererEventListener listener)
Removes a listener to receive debug events from the video renderer.
|
void |
removeVideoListener(SimpleExoPlayer.VideoListener listener)
Removes a listener of video events.
|
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)
Deprecated.
|
void |
setAudioStreamType(int streamType)
Deprecated.
|
void |
setMetadataOutput(MetadataOutput output)
Deprecated.
|
void |
setPlaybackParameters(PlaybackParameters playbackParameters)
Attempts to set the playback parameters.
|
void |
setPlaybackParams(android.media.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 |
setShuffleModeEnabled(boolean shuffleModeEnabled)
Sets whether shuffling of windows is enabled.
|
void |
setTextOutput(TextOutput output)
Deprecated.
|
void |
setVideoDebugListener(VideoRendererEventListener listener)
Deprecated.
|
void |
setVideoListener(SimpleExoPlayer.VideoListener listener)
Deprecated.
|
void |
setVideoScalingMode(int videoScalingMode)
Sets the video scaling mode.
|
void |
setVideoSurface(android.view.Surface surface)
Sets the
Surface onto which video will be rendered. |
void |
setVideoSurfaceHolder(android.view.SurfaceHolder surfaceHolder)
Sets the
SurfaceHolder that holds the Surface onto which video will be
rendered. |
void |
setVideoSurfaceView(android.view.SurfaceView surfaceView)
Sets the
SurfaceView onto which video will be rendered. |
void |
setVideoTextureView(android.view.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()
Surface
, SurfaceHolder
, SurfaceView
or TextureView
currently set on the player.public void setVideoSurface(android.view.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(android.view.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(android.view.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(android.view.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(android.view.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(android.view.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(android.view.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(android.view.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 android.media.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 addVideoListener(SimpleExoPlayer.VideoListener listener)
listener
- The listener to register.public void removeVideoListener(SimpleExoPlayer.VideoListener listener)
listener
- The listener to unregister.@Deprecated public void setVideoListener(SimpleExoPlayer.VideoListener listener)
addVideoListener(VideoListener)
.listener
- The listener.@Deprecated public void clearVideoListener(SimpleExoPlayer.VideoListener listener)
removeVideoListener(VideoListener)
.removeVideoListener(VideoListener)
.listener
- The listener to clear.public void addTextOutput(TextOutput listener)
listener
- The output to register.public void removeTextOutput(TextOutput listener)
listener
- The output to remove.@Deprecated public void setTextOutput(TextOutput output)
addTextOutput(TextOutput)
.output
- The output.@Deprecated public void clearTextOutput(TextOutput output)
removeTextOutput(TextOutput)
.removeTextOutput(TextOutput)
.output
- The output to clear.public void addMetadataOutput(MetadataOutput listener)
listener
- The output to register.public void removeMetadataOutput(MetadataOutput listener)
listener
- The output to remove.@Deprecated public void setMetadataOutput(MetadataOutput output)
addMetadataOutput(MetadataOutput)
.output
- The output.@Deprecated public void clearMetadataOutput(MetadataOutput output)
removeMetadataOutput(MetadataOutput)
.removeMetadataOutput(MetadataOutput)
.output
- The output to clear.@Deprecated public void setVideoDebugListener(VideoRendererEventListener listener)
addVideoDebugListener(VideoRendererEventListener)
.listener
- The listener.public void addVideoDebugListener(VideoRendererEventListener listener)
listener
- The listener.public void removeVideoDebugListener(VideoRendererEventListener listener)
listener
- The listener.@Deprecated public void setAudioDebugListener(AudioRendererEventListener listener)
addAudioDebugListener(AudioRendererEventListener)
.listener
- The listener.public void addAudioDebugListener(AudioRendererEventListener listener)
listener
- The listener.public void removeAudioDebugListener(AudioRendererEventListener listener)
listener
- The listener.public android.os.Looper getPlaybackLooper()
ExoPlayer
Looper
associated with the playback thread.getPlaybackLooper
in interface ExoPlayer
Looper
associated with the playback thread.public void addListener(Player.EventListener listener)
Player
Looper
, then the listener will be called on the main thread.addListener
in interface Player
listener
- The listener to register.public void removeListener(Player.EventListener listener)
Player
removeListener
in interface Player
listener
- The listener to unregister.public int getPlaybackState()
Player
getPlaybackState
in interface Player
STATE
constants defined in this interface.public void prepare(MediaSource mediaSource)
ExoPlayer
MediaSource
. Equivalent to
prepare(mediaSource, true, true)
.
Note: MediaSource
instances are not designed to be re-used. If you want to prepare a
player more than once with the same piece of media, use a new instance each time.
public void prepare(MediaSource mediaSource, boolean resetPosition, boolean resetState)
ExoPlayer
MediaSource
, optionally resetting the playback
position the default position in the first Timeline.Window
.
Note: MediaSource
instances are not designed to be re-used. If you want to prepare a
player more than once with the same piece of media, use a new instance each time.
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 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)
Player
Player.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 Player
playWhenReady
- Whether playback should proceed when ready.public boolean getPlayWhenReady()
Player
Player.getPlaybackState()
== Player.STATE_READY
.getPlayWhenReady
in interface Player
public int getRepeatMode()
Player
Player.RepeatMode
used for playback.getRepeatMode
in interface Player
public void setRepeatMode(int repeatMode)
Player
Player.RepeatMode
to be used for playback.setRepeatMode
in interface Player
repeatMode
- A repeat mode.public void setShuffleModeEnabled(boolean shuffleModeEnabled)
Player
setShuffleModeEnabled
in interface Player
shuffleModeEnabled
- Whether shuffling is enabled.public boolean getShuffleModeEnabled()
Player
getShuffleModeEnabled
in interface Player
public boolean isLoading()
Player
public void seekToDefaultPosition()
Player
seekToDefaultPosition
in interface Player
public void seekToDefaultPosition(int windowIndex)
Player
seekToDefaultPosition
in interface Player
windowIndex
- The index of the window whose associated default position should be seeked
to.public void seekTo(long positionMs)
Player
seekTo
in interface Player
positionMs
- 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)
Player
seekTo
in interface Player
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.public void setPlaybackParameters(@Nullable PlaybackParameters playbackParameters)
Player
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.
setPlaybackParameters
in interface Player
playbackParameters
- The playback parameters, or null
to use the defaults.public PlaybackParameters getPlaybackParameters()
Player
getPlaybackParameters
in interface Player
Player.EventListener.onPlaybackParametersChanged(PlaybackParameters)
public void stop()
Player
setPlayWhenReady(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()
Player
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 getRendererCount()
Player
getRendererCount
in interface Player
public int getRendererType(int index)
Player
getRendererType
in interface Player
index
- The index of the renderer.TRACK_TYPE_*
constants defined in C
.Renderer.getTrackType()
public TrackGroupArray getCurrentTrackGroups()
Player
getCurrentTrackGroups
in interface Player
public TrackSelectionArray getCurrentTrackSelections()
Player
getCurrentTrackSelections
in interface Player
public Timeline getCurrentTimeline()
Player
Timeline
. Never null, but may be empty.getCurrentTimeline
in interface Player
public java.lang.Object getCurrentManifest()
Player
getCurrentManifest
in interface Player
public int getCurrentPeriodIndex()
Player
getCurrentPeriodIndex
in interface Player
public int getCurrentWindowIndex()
Player
getCurrentWindowIndex
in interface Player
public int getNextWindowIndex()
Player
C.INDEX_UNSET
if the window
currently being played is the last window.getNextWindowIndex
in interface Player
public int getPreviousWindowIndex()
Player
C.INDEX_UNSET
if the window
currently being played is the first window.getPreviousWindowIndex
in interface Player
public long getDuration()
Player
C.TIME_UNSET
if the
duration is not known.getDuration
in interface Player
public long getCurrentPosition()
Player
getCurrentPosition
in interface Player
public long getBufferedPosition()
Player
getBufferedPosition
in interface Player
public int getBufferedPercentage()
Player
getBufferedPercentage
in interface Player
public boolean isCurrentWindowDynamic()
Player
false
if the Timeline
is
empty.isCurrentWindowDynamic
in interface Player
Timeline.Window.isDynamic
public boolean isCurrentWindowSeekable()
Player
false
if the Timeline
is
empty.isCurrentWindowSeekable
in interface Player
Timeline.Window.isSeekable
public boolean isPlayingAd()
Player
isPlayingAd
in interface Player
public int getCurrentAdGroupIndex()
Player
Player.isPlayingAd()
returns true, returns the index of the ad group in the period
currently being played. Returns C.INDEX_UNSET
otherwise.getCurrentAdGroupIndex
in interface Player
public int getCurrentAdIndexInAdGroup()
Player
Player.isPlayingAd()
returns true, returns the index of the ad in its ad group. Returns
C.INDEX_UNSET
otherwise.getCurrentAdIndexInAdGroup
in interface Player
public long getContentPosition()
Player
Player.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
protected ExoPlayer createExoPlayerImpl(Renderer[] renderers, TrackSelector trackSelector, LoadControl loadControl)
ExoPlayer
implementation used by this instance.renderers
- The Renderer
s that will be used by the instance.trackSelector
- The TrackSelector
that will be used by the instance.loadControl
- The LoadControl
that will be used by the instance.ExoPlayer
instance.