public class SimpleExoPlayer extends BasePlayer implements ExoPlayer, Player.AudioComponent, Player.VideoComponent, Player.TextComponent, Player.MetadataComponent
ExoPlayer
implementation that uses default Renderer
components. Instances can
be obtained from ExoPlayerFactory
.Modifier and Type | Class and Description |
---|---|
static interface |
SimpleExoPlayer.VideoListener
Deprecated.
Use
VideoListener . |
ExoPlayer.EventListener, ExoPlayer.ExoPlayerComponent, ExoPlayer.ExoPlayerMessage
Player.AudioComponent, Player.DefaultEventListener, Player.DiscontinuityReason, Player.MetadataComponent, Player.RepeatMode, Player.TextComponent, Player.TimelineChangeReason, Player.VideoComponent
Modifier and Type | Field and Description |
---|---|
protected Renderer[] |
renderers |
window
REPEAT_MODE_ALL, REPEAT_MODE_OFF, REPEAT_MODE_ONE, STATE_BUFFERING, STATE_ENDED, STATE_IDLE, STATE_READY
DISCONTINUITY_REASON_AD_INSERTION, DISCONTINUITY_REASON_INTERNAL, DISCONTINUITY_REASON_PERIOD_TRANSITION, DISCONTINUITY_REASON_SEEK, DISCONTINUITY_REASON_SEEK_ADJUSTMENT, TIMELINE_CHANGE_REASON_DYNAMIC, TIMELINE_CHANGE_REASON_PREPARED, TIMELINE_CHANGE_REASON_RESET
Modifier | Constructor and Description |
---|---|
protected |
SimpleExoPlayer(android.content.Context context,
RenderersFactory renderersFactory,
TrackSelector trackSelector,
LoadControl loadControl,
BandwidthMeter bandwidthMeter,
DrmSessionManager<FrameworkMediaCrypto> drmSessionManager,
android.os.Looper looper) |
protected |
SimpleExoPlayer(android.content.Context context,
RenderersFactory renderersFactory,
TrackSelector trackSelector,
LoadControl loadControl,
DrmSessionManager<FrameworkMediaCrypto> drmSessionManager,
BandwidthMeter bandwidthMeter,
AnalyticsCollector.Factory analyticsCollectorFactory,
Clock clock,
android.os.Looper looper) |
protected |
SimpleExoPlayer(android.content.Context context,
RenderersFactory renderersFactory,
TrackSelector trackSelector,
LoadControl loadControl,
DrmSessionManager<FrameworkMediaCrypto> drmSessionManager,
BandwidthMeter bandwidthMeter,
AnalyticsCollector.Factory analyticsCollectorFactory,
android.os.Looper looper) |
Modifier and Type | Method and Description |
---|---|
void |
addAnalyticsListener(AnalyticsListener listener)
Adds an
AnalyticsListener to receive analytics events. |
void |
addAudioDebugListener(AudioRendererEventListener listener)
Deprecated.
Use
addAnalyticsListener(AnalyticsListener) to get more detailed debug
information. |
void |
addAudioListener(AudioListener listener)
Adds a listener to receive audio events.
|
void |
addListener(Player.EventListener listener)
Register a listener to receive events from the player.
|
void |
addMetadataOutput(MetadataOutput listener)
Adds a
MetadataOutput to receive metadata. |
void |
addTextOutput(TextOutput listener)
Registers an output to receive text events.
|
void |
addVideoDebugListener(VideoRendererEventListener listener)
Deprecated.
Use
addAnalyticsListener(AnalyticsListener) to get more detailed debug
information. |
void |
addVideoListener(VideoListener listener)
Adds a listener to receive video events.
|
void |
blockingSendMessages(ExoPlayer.ExoPlayerMessage... messages)
Deprecated.
|
void |
clearAuxEffectInfo()
Detaches any previously attached auxiliary audio effect from the underlying audio track.
|
void |
clearCameraMotionListener(CameraMotionListener listener)
Clears the listener which receives camera motion events if it matches the one passed.
|
void |
clearMetadataOutput(MetadataOutput output)
Deprecated.
|
void |
clearTextOutput(TextOutput output)
Deprecated.
|
void |
clearVideoFrameMetadataListener(VideoFrameMetadataListener listener)
Clears the listener which receives video frame metadata events if it matches the one passed.
|
void |
clearVideoListener(SimpleExoPlayer.VideoListener listener)
|
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. |
PlayerMessage |
createMessage(PlayerMessage.Target target)
Creates a message that can be sent to a
PlayerMessage.Target . |
AnalyticsCollector |
getAnalyticsCollector()
Returns the
AnalyticsCollector used for collecting analytics events. |
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. |
AudioAttributes |
getAudioAttributes()
Returns the attributes for audio playback.
|
Player.AudioComponent |
getAudioComponent()
Returns the component of this player for audio output, or null if audio is not supported.
|
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() . |
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
Player.isPlayingAd() returns true , returns an estimate of the content position in
the current content 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 content window or ad, 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 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.
|
ExoPlaybackException |
getPlaybackError()
Returns the error that caused playback to fail.
|
android.os.Looper |
getPlaybackLooper()
Returns 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. |
SeekParameters |
getSeekParameters()
Returns the currently active
SeekParameters of the player. |
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.
|
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
C.VideoScalingMode . |
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.
|
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 |
removeAnalyticsListener(AnalyticsListener listener)
Removes an
AnalyticsListener . |
void |
removeAudioDebugListener(AudioRendererEventListener listener)
Deprecated.
Use
addAnalyticsListener(AnalyticsListener) and removeAnalyticsListener(AnalyticsListener) to get more detailed debug information. |
void |
removeAudioListener(AudioListener listener)
Removes a listener of audio events.
|
void |
removeListener(Player.EventListener listener)
Unregister a listener.
|
void |
removeMetadataOutput(MetadataOutput listener)
Removes a
MetadataOutput . |
void |
removeTextOutput(TextOutput listener)
Removes a text output.
|
void |
removeVideoDebugListener(VideoRendererEventListener listener)
Deprecated.
Use
addAnalyticsListener(AnalyticsListener) and removeAnalyticsListener(AnalyticsListener) to get more detailed debug information. |
void |
removeVideoListener(VideoListener listener)
Removes a listener of video events.
|
void |
retry()
Retries a failed or stopped playback.
|
void |
seekTo(int windowIndex,
long positionMs)
Seeks to a position specified in milliseconds in the specified window.
|
void |
sendMessages(ExoPlayer.ExoPlayerMessage... messages)
Deprecated.
|
void |
setAudioAttributes(AudioAttributes audioAttributes)
Sets the attributes for audio playback, used by the underlying audio track.
|
void |
setAudioAttributes(AudioAttributes audioAttributes,
boolean handleAudioFocus)
Sets the attributes for audio playback, used by the underlying audio track.
|
void |
setAudioDebugListener(AudioRendererEventListener listener)
Deprecated.
Use
addAnalyticsListener(AnalyticsListener) to get more detailed debug
information. |
void |
setAudioStreamType(int streamType)
Deprecated.
|
void |
setAuxEffectInfo(AuxEffectInfo auxEffectInfo)
Sets information on an auxiliary audio effect to attach to the underlying audio track.
|
void |
setCameraMotionListener(CameraMotionListener listener)
Sets a listener of camera motion events.
|
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 |
setSeekParameters(SeekParameters seekParameters)
Sets the parameters that control how seek operations are performed.
|
void |
setShuffleModeEnabled(boolean shuffleModeEnabled)
Sets whether shuffling of windows is enabled.
|
void |
setTextOutput(TextOutput output)
Deprecated.
|
void |
setVideoDebugListener(VideoRendererEventListener listener)
Deprecated.
Use
addAnalyticsListener(AnalyticsListener) to get more detailed debug
information. |
void |
setVideoFrameMetadataListener(VideoFrameMetadataListener listener)
Sets a listener to receive video frame metadata events.
|
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(boolean reset)
Stops playback and optionally resets the player.
|
getBufferedPercentage, getContentDuration, getCurrentTag, getNextWindowIndex, getPreviousWindowIndex, hasNext, hasPrevious, isCurrentWindowDynamic, isCurrentWindowSeekable, next, previous, seekTo, seekToDefaultPosition, seekToDefaultPosition, stop
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getBufferedPercentage, getContentDuration, getCurrentTag, getNextWindowIndex, getPreviousWindowIndex, hasNext, hasPrevious, isCurrentWindowDynamic, isCurrentWindowSeekable, next, previous, seekTo, seekToDefaultPosition, seekToDefaultPosition, stop
protected final Renderer[] renderers
protected SimpleExoPlayer(android.content.Context context, RenderersFactory renderersFactory, TrackSelector trackSelector, LoadControl loadControl, BandwidthMeter bandwidthMeter, @Nullable DrmSessionManager<FrameworkMediaCrypto> drmSessionManager, android.os.Looper looper)
context
- A Context
.renderersFactory
- A factory for creating Renderer
s to 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.bandwidthMeter
- The BandwidthMeter
that will be used by the instance.drmSessionManager
- An optional DrmSessionManager
. May be null if the instance
will not be used for DRM protected playbacks.looper
- The Looper
which must be used for all calls to the player and which is
used to call listeners on.protected SimpleExoPlayer(android.content.Context context, RenderersFactory renderersFactory, TrackSelector trackSelector, LoadControl loadControl, @Nullable DrmSessionManager<FrameworkMediaCrypto> drmSessionManager, BandwidthMeter bandwidthMeter, AnalyticsCollector.Factory analyticsCollectorFactory, android.os.Looper looper)
context
- A Context
.renderersFactory
- A factory for creating Renderer
s to 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.drmSessionManager
- An optional DrmSessionManager
. May be null if the instance
will not be used for DRM protected playbacks.bandwidthMeter
- The BandwidthMeter
that will be used by the instance.analyticsCollectorFactory
- A factory for creating the AnalyticsCollector
that
will collect and forward all player events.looper
- The Looper
which must be used for all calls to the player and which is
used to call listeners on.protected SimpleExoPlayer(android.content.Context context, RenderersFactory renderersFactory, TrackSelector trackSelector, LoadControl loadControl, @Nullable DrmSessionManager<FrameworkMediaCrypto> drmSessionManager, BandwidthMeter bandwidthMeter, AnalyticsCollector.Factory analyticsCollectorFactory, Clock clock, android.os.Looper looper)
context
- A Context
.renderersFactory
- A factory for creating Renderer
s to 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.drmSessionManager
- An optional DrmSessionManager
. May be null if the instance
will not be used for DRM protected playbacks.bandwidthMeter
- The BandwidthMeter
that will be used by the instance.analyticsCollectorFactory
- A factory for creating the AnalyticsCollector
that
will collect and forward all player events.clock
- The Clock
that will be used by the instance. Should always be Clock.DEFAULT
, unless the player is being used from a test.looper
- The Looper
which must be used for all calls to the player and which is
used to call listeners on.@Nullable public Player.AudioComponent getAudioComponent()
Player
getAudioComponent
in interface Player
@Nullable public Player.VideoComponent getVideoComponent()
Player
getVideoComponent
in interface Player
@Nullable public Player.TextComponent getTextComponent()
Player
getTextComponent
in interface Player
@Nullable public Player.MetadataComponent getMetadataComponent()
Player
getMetadataComponent
in interface Player
public void setVideoScalingMode(@C.VideoScalingMode 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
.
setVideoScalingMode
in interface Player.VideoComponent
videoScalingMode
- The video scaling mode.@C.VideoScalingMode public int getVideoScalingMode()
Player.VideoComponent
C.VideoScalingMode
.getVideoScalingMode
in interface Player.VideoComponent
public void clearVideoSurface()
Player.VideoComponent
Surface
, SurfaceHolder
, SurfaceView
or TextureView
currently set on the player.clearVideoSurface
in interface Player.VideoComponent
public void clearVideoSurface(android.view.Surface surface)
Player.VideoComponent
Surface
onto which video is being rendered if it matches the one passed.
Else does nothing.clearVideoSurface
in interface Player.VideoComponent
surface
- The surface to clear.public void setVideoSurface(@Nullable android.view.Surface surface)
Player.VideoComponent
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 Player.VideoComponent.setVideoSurfaceView(SurfaceView)
, Player.VideoComponent.setVideoTextureView(TextureView)
or Player.VideoComponent.setVideoSurfaceHolder(SurfaceHolder)
rather
than this method, since passing the holder allows the player to track the lifecycle of the
surface automatically.
setVideoSurface
in interface Player.VideoComponent
surface
- The Surface
.public void setVideoSurfaceHolder(android.view.SurfaceHolder surfaceHolder)
Player.VideoComponent
SurfaceHolder
that holds the Surface
onto which video will be
rendered. The player will track the lifecycle of the surface automatically.setVideoSurfaceHolder
in interface Player.VideoComponent
surfaceHolder
- The surface holder.public void clearVideoSurfaceHolder(android.view.SurfaceHolder surfaceHolder)
Player.VideoComponent
SurfaceHolder
that holds the Surface
onto which video is being
rendered if it matches the one passed. Else does nothing.clearVideoSurfaceHolder
in interface Player.VideoComponent
surfaceHolder
- The surface holder to clear.public void setVideoSurfaceView(android.view.SurfaceView surfaceView)
Player.VideoComponent
SurfaceView
onto which video will be rendered. The player will track the
lifecycle of the surface automatically.setVideoSurfaceView
in interface Player.VideoComponent
surfaceView
- The surface view.public void clearVideoSurfaceView(android.view.SurfaceView surfaceView)
Player.VideoComponent
SurfaceView
onto which video is being rendered if it matches the one
passed. Else does nothing.clearVideoSurfaceView
in interface Player.VideoComponent
surfaceView
- The texture view to clear.public void setVideoTextureView(android.view.TextureView textureView)
Player.VideoComponent
TextureView
onto which video will be rendered. The player will track the
lifecycle of the surface automatically.setVideoTextureView
in interface Player.VideoComponent
textureView
- The texture view.public void clearVideoTextureView(android.view.TextureView textureView)
Player.VideoComponent
TextureView
onto which video is being rendered if it matches the one
passed. Else does nothing.clearVideoTextureView
in interface Player.VideoComponent
textureView
- The texture view to clear.public void addAudioListener(AudioListener listener)
Player.AudioComponent
addAudioListener
in interface Player.AudioComponent
listener
- The listener to register.public void removeAudioListener(AudioListener listener)
Player.AudioComponent
removeAudioListener
in interface Player.AudioComponent
listener
- The listener to unregister.public void setAudioAttributes(AudioAttributes audioAttributes)
Player.AudioComponent
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)
.
setAudioAttributes
in interface Player.AudioComponent
audioAttributes
- The attributes to use for audio playback.public void setAudioAttributes(AudioAttributes audioAttributes, boolean handleAudioFocus)
Player.AudioComponent
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)
.
If audio focus should be handled, the AudioAttributes.usage
must be C.USAGE_MEDIA
or C.USAGE_GAME
. Other usages will throw an IllegalArgumentException
.
setAudioAttributes
in interface Player.AudioComponent
audioAttributes
- The attributes to use for audio playback.handleAudioFocus
- True if the player should handle audio focus, false otherwise.public AudioAttributes getAudioAttributes()
Player.AudioComponent
getAudioAttributes
in interface Player.AudioComponent
public int getAudioSessionId()
Player.AudioComponent
C.AUDIO_SESSION_ID_UNSET
if not set.getAudioSessionId
in interface Player.AudioComponent
public void setAuxEffectInfo(AuxEffectInfo auxEffectInfo)
Player.AudioComponent
setAuxEffectInfo
in interface Player.AudioComponent
public void clearAuxEffectInfo()
Player.AudioComponent
clearAuxEffectInfo
in interface Player.AudioComponent
public void setVolume(float audioVolume)
Player.AudioComponent
setVolume
in interface Player.AudioComponent
audioVolume
- The audio volume.public float getVolume()
Player.AudioComponent
getVolume
in interface Player.AudioComponent
@Deprecated public void setAudioStreamType(@C.StreamType 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 @C.StreamType public int getAudioStreamType()
getAudioAttributes()
.public AnalyticsCollector getAnalyticsCollector()
AnalyticsCollector
used for collecting analytics events.public void addAnalyticsListener(AnalyticsListener listener)
AnalyticsListener
to receive analytics events.listener
- The listener to be added.public void removeAnalyticsListener(AnalyticsListener listener)
AnalyticsListener
.listener
- The listener to be removed.@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 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(VideoListener listener)
Player.VideoComponent
addVideoListener
in interface Player.VideoComponent
listener
- The listener to register.public void removeVideoListener(VideoListener listener)
Player.VideoComponent
removeVideoListener
in interface Player.VideoComponent
listener
- The listener to unregister.public void setVideoFrameMetadataListener(VideoFrameMetadataListener listener)
Player.VideoComponent
This method is intended to be called by the same component that sets the Surface
onto which video will be rendered. If using ExoPlayer's standard UI components, this method
should not be called directly from application code.
setVideoFrameMetadataListener
in interface Player.VideoComponent
listener
- The listener.public void clearVideoFrameMetadataListener(VideoFrameMetadataListener listener)
Player.VideoComponent
clearVideoFrameMetadataListener
in interface Player.VideoComponent
listener
- The listener to clear.public void setCameraMotionListener(CameraMotionListener listener)
Player.VideoComponent
setCameraMotionListener
in interface Player.VideoComponent
listener
- The listener.public void clearCameraMotionListener(CameraMotionListener listener)
Player.VideoComponent
clearCameraMotionListener
in interface Player.VideoComponent
listener
- The listener to clear.@Deprecated public void setVideoListener(SimpleExoPlayer.VideoListener listener)
addVideoListener(com.google.android.exoplayer2.video.VideoListener)
.listener
- The listener.@Deprecated public void clearVideoListener(SimpleExoPlayer.VideoListener listener)
listener
- The listener to clear.public void addTextOutput(TextOutput listener)
Player.TextComponent
addTextOutput
in interface Player.TextComponent
listener
- The output to register.public void removeTextOutput(TextOutput listener)
Player.TextComponent
removeTextOutput
in interface Player.TextComponent
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)
Player.MetadataComponent
MetadataOutput
to receive metadata.addMetadataOutput
in interface Player.MetadataComponent
listener
- The output to register.public void removeMetadataOutput(MetadataOutput listener)
Player.MetadataComponent
MetadataOutput
.removeMetadataOutput
in interface Player.MetadataComponent
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)
addAnalyticsListener(AnalyticsListener)
to get more detailed debug
information.@Deprecated public void addVideoDebugListener(VideoRendererEventListener listener)
addAnalyticsListener(AnalyticsListener)
to get more detailed debug
information.@Deprecated public void removeVideoDebugListener(VideoRendererEventListener listener)
addAnalyticsListener(AnalyticsListener)
and removeAnalyticsListener(AnalyticsListener)
to get more detailed debug information.@Deprecated public void setAudioDebugListener(AudioRendererEventListener listener)
addAnalyticsListener(AnalyticsListener)
to get more detailed debug
information.@Deprecated public void addAudioDebugListener(AudioRendererEventListener listener)
addAnalyticsListener(AnalyticsListener)
to get more detailed debug
information.@Deprecated public void removeAudioDebugListener(AudioRendererEventListener listener)
addAnalyticsListener(AnalyticsListener)
and removeAnalyticsListener(AnalyticsListener)
to get more detailed debug information.public android.os.Looper getPlaybackLooper()
ExoPlayer
Looper
associated with the playback thread.getPlaybackLooper
in interface ExoPlayer
public android.os.Looper getApplicationLooper()
Player
Looper
associated with the application thread that's used to access the
player and on which player events are received.getApplicationLooper
in interface Player
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.@Nullable public ExoPlaybackException getPlaybackError()
Player
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.getPlaybackError
in interface Player
null
.public void retry()
ExoPlayer
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
@Player.RepeatMode public int getRepeatMode()
Player
Player.RepeatMode
used for playback.getRepeatMode
in interface Player
public void setRepeatMode(@Player.RepeatMode 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 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 setSeekParameters(@Nullable SeekParameters seekParameters)
ExoPlayer
setSeekParameters
in interface ExoPlayer
seekParameters
- The seek parameters, or null
to use the defaults.public SeekParameters getSeekParameters()
ExoPlayer
SeekParameters
of the player.getSeekParameters
in interface ExoPlayer
public void stop(boolean reset)
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.
public void release()
Player
@Deprecated public void sendMessages(ExoPlayer.ExoPlayerMessage... messages)
sendMessages
in interface ExoPlayer
public PlayerMessage createMessage(PlayerMessage.Target target)
ExoPlayer
PlayerMessage.Target
. By default, the message
will be delivered immediately without blocking on the playback thread. The default PlayerMessage.getType()
is 0 and the default PlayerMessage.getPayload()
is null. If a
position is specified with PlayerMessage.setPosition(long)
, the message will be
delivered at this position in the current window defined by Player.getCurrentWindowIndex()
.
Alternatively, the message can be sent at a specific window using PlayerMessage.setPosition(int, long)
.createMessage
in interface ExoPlayer
@Deprecated public void blockingSendMessages(ExoPlayer.ExoPlayerMessage... messages)
blockingSendMessages
in interface ExoPlayer
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
@Nullable 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 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 long getTotalBufferedDuration()
Player
getTotalBufferedDuration
in interface Player
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
public long getContentBufferedPosition()
Player
Player.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 Player.getBufferedPosition()
.getContentBufferedPosition
in interface Player