public interface ExoPlayer extends Player
MediaSources. Instances can be obtained from ExoPlayerFactory.
ExoPlayer is designed to make few assumptions about (and hence impose few restrictions on) the type of the media being played, how and where it is stored, and how it is rendered. Rather than implementing the loading and rendering of media directly, ExoPlayer implementations delegate this work to components that are injected when a player is created or when it's prepared for playback. Components common to all ExoPlayer implementations are:
MediaSource that defines the media to be played, loads the media, and from
which the loaded media can be read. A MediaSource is injected via prepare(MediaSource) at the start of playback. The library modules provide default
implementations for regular media files (ExtractorMediaSource), DASH
(DashMediaSource), SmoothStreaming (SsMediaSource) and HLS (HlsMediaSource), an
implementation for loading single media samples (SingleSampleMediaSource) that's
most often used for side-loaded subtitle files, and implementations for building more
complex MediaSources from simpler ones (MergingMediaSource, ConcatenatingMediaSource, LoopingMediaSource and ClippingMediaSource).
Renderers that render individual components of the media. The library
provides default implementations for common media types (MediaCodecVideoRenderer,
MediaCodecAudioRenderer, TextRenderer and MetadataRenderer). A
Renderer consumes media from the MediaSource being played. Renderers are injected when the
player is created.
TrackSelector that selects tracks provided by the MediaSource to be
consumed by each of the available Renderers. The library provides a default implementation
(DefaultTrackSelector) suitable for most use cases. A TrackSelector is injected
when the player is created.
LoadControl that controls when the MediaSource buffers more media, and how
much media is buffered. The library provides a default implementation (DefaultLoadControl) suitable for most use cases. A LoadControl is injected when the player
is created.
An ExoPlayer can be built using the default components provided by the library, but may also be built using custom implementations if non-standard behaviors are required. For example a custom LoadControl could be injected to change the player's buffering strategy, or a custom Renderer could be injected to add support for a video codec not supported natively by Android.
The concept of injecting components that implement pieces of player functionality is present
throughout the library. The default component implementations listed above delegate work to
further injected components. This allows many sub-components to be individually replaced with
custom implementations. For example the default MediaSource implementations require one or more
DataSource factories to be injected via their constructors. By providing a custom factory
it's possible to load data from a non-standard source, or through a different network stack.
The figure below shows ExoPlayer's threading model.
Player.getApplicationLooper().
Player.getApplicationLooper(). Note that this means registered listeners are called on the same
thread which must be used to access the player.
| Modifier and Type | Interface and Description |
|---|---|
static interface |
ExoPlayer.EventListener
Deprecated.
Use
Player.EventListener instead. |
static interface |
ExoPlayer.ExoPlayerComponent
Deprecated.
Use
PlayerMessage.Target instead. |
static class |
ExoPlayer.ExoPlayerMessage
Deprecated.
Use
PlayerMessage instead. |
Player.AudioComponent, Player.DefaultEventListener, Player.DiscontinuityReason, Player.MetadataComponent, Player.RepeatMode, Player.TextComponent, Player.TimelineChangeReason, Player.VideoComponent| Modifier and Type | Field and Description |
|---|---|
static int |
REPEAT_MODE_ALL
Deprecated.
Use
Player.REPEAT_MODE_ALL instead. |
static int |
REPEAT_MODE_OFF
Deprecated.
Use
Player.REPEAT_MODE_OFF instead. |
static int |
REPEAT_MODE_ONE
Deprecated.
Use
Player.REPEAT_MODE_ONE instead. |
static int |
STATE_BUFFERING
Deprecated.
Use
Player.STATE_BUFFERING instead. |
static int |
STATE_ENDED
Deprecated.
Use
Player.STATE_ENDED instead. |
static int |
STATE_IDLE
Deprecated.
Use
Player.STATE_IDLE instead. |
static int |
STATE_READY
Deprecated.
Use
Player.STATE_READY instead. |
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 and Type | Method and Description |
|---|---|
void |
blockingSendMessages(ExoPlayer.ExoPlayerMessage... messages)
Deprecated.
|
PlayerMessage |
createMessage(PlayerMessage.Target target)
Creates a message that can be sent to a
PlayerMessage.Target. |
android.os.Looper |
getPlaybackLooper()
Returns the
Looper associated with the playback thread. |
SeekParameters |
getSeekParameters()
Returns the currently active
SeekParameters of the player. |
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 |
retry()
Retries a failed or stopped playback.
|
void |
sendMessages(ExoPlayer.ExoPlayerMessage... messages)
Deprecated.
Use
createMessage(PlayerMessage.Target) instead. |
void |
setSeekParameters(SeekParameters seekParameters)
Sets the parameters that control how seek operations are performed.
|
addListener, getApplicationLooper, getAudioComponent, getBufferedPercentage, getBufferedPosition, getContentBufferedPosition, getContentDuration, getContentPosition, getCurrentAdGroupIndex, getCurrentAdIndexInAdGroup, getCurrentManifest, getCurrentPeriodIndex, getCurrentPosition, getCurrentTag, getCurrentTimeline, getCurrentTrackGroups, getCurrentTrackSelections, getCurrentWindowIndex, getDuration, getMetadataComponent, getNextWindowIndex, getPlaybackError, getPlaybackParameters, getPlaybackState, getPlayWhenReady, getPreviousWindowIndex, getRendererCount, getRendererType, getRepeatMode, getShuffleModeEnabled, getTextComponent, getTotalBufferedDuration, getVideoComponent, hasNext, hasPrevious, isCurrentWindowDynamic, isCurrentWindowSeekable, isLoading, isPlayingAd, next, previous, release, removeListener, seekTo, seekTo, seekToDefaultPosition, seekToDefaultPosition, setPlaybackParameters, setPlayWhenReady, setRepeatMode, setShuffleModeEnabled, stop, stop@Deprecated static final int STATE_IDLE
Player.STATE_IDLE instead.@Deprecated static final int STATE_BUFFERING
Player.STATE_BUFFERING instead.@Deprecated static final int STATE_READY
Player.STATE_READY instead.@Deprecated static final int STATE_ENDED
Player.STATE_ENDED instead.@Deprecated @Player.RepeatMode static final int REPEAT_MODE_OFF
Player.REPEAT_MODE_OFF instead.@Deprecated @Player.RepeatMode static final int REPEAT_MODE_ONE
Player.REPEAT_MODE_ONE instead.@Deprecated @Player.RepeatMode static final int REPEAT_MODE_ALL
Player.REPEAT_MODE_ALL instead.android.os.Looper getPlaybackLooper()
Looper associated with the playback thread.void retry()
void prepare(MediaSource mediaSource)
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.
void prepare(MediaSource mediaSource, boolean resetPosition, boolean resetState)
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.
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).PlayerMessage createMessage(PlayerMessage.Target target)
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).@Deprecated void sendMessages(ExoPlayer.ExoPlayerMessage... messages)
createMessage(PlayerMessage.Target) instead.@Deprecated void blockingSendMessages(ExoPlayer.ExoPlayerMessage... messages)
createMessage(PlayerMessage.Target) with PlayerMessage.blockUntilDelivered().void setSeekParameters(@Nullable
SeekParameters seekParameters)
seekParameters - The seek parameters, or null to use the defaults.SeekParameters getSeekParameters()
SeekParameters of the player.