public interface ExoPlayer extends Player
MediaSource
s. 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
,
DynamicConcatenatingMediaSource
, LoopingMediaSource
and
ClippingMediaSource
).Renderer
s 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.
Looper
. In that case,
registered listeners will be called on the application's main thread.Modifier and Type | Interface and Description |
---|---|
static interface |
ExoPlayer.EventListener
Deprecated.
Use
Player.EventListener instead. |
static interface |
ExoPlayer.ExoPlayerComponent
A component of an
ExoPlayer that can receive messages on the playback thread. |
static class |
ExoPlayer.ExoPlayerMessage
Defines a message and a target
ExoPlayer.ExoPlayerComponent to receive it. |
Player.DefaultEventListener, Player.DiscontinuityReason, Player.RepeatMode
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_INTERNAL, DISCONTINUITY_REASON_PERIOD_TRANSITION, DISCONTINUITY_REASON_SEEK, DISCONTINUITY_REASON_SEEK_ADJUSTMENT
Modifier and Type | Method and Description |
---|---|
void |
blockingSendMessages(ExoPlayer.ExoPlayerMessage... messages)
Variant of
sendMessages(ExoPlayerMessage...) that blocks until after the messages have
been delivered. |
android.os.Looper |
getPlaybackLooper()
Gets the
Looper associated with the playback thread. |
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 |
sendMessages(ExoPlayer.ExoPlayerMessage... messages)
Sends messages to their target components.
|
addListener, getBufferedPercentage, getBufferedPosition, getContentPosition, getCurrentAdGroupIndex, getCurrentAdIndexInAdGroup, getCurrentManifest, getCurrentPeriodIndex, getCurrentPosition, getCurrentTimeline, getCurrentTrackGroups, getCurrentTrackSelections, getCurrentWindowIndex, getDuration, getNextWindowIndex, getPlaybackParameters, getPlaybackState, getPlayWhenReady, getPreviousWindowIndex, getRendererCount, getRendererType, getRepeatMode, getShuffleModeEnabled, isCurrentWindowDynamic, isCurrentWindowSeekable, isLoading, isPlayingAd, release, removeListener, seekTo, seekTo, seekToDefaultPosition, seekToDefaultPosition, setPlaybackParameters, setPlayWhenReady, setRepeatMode, setShuffleModeEnabled, 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 static final int REPEAT_MODE_OFF
Player.REPEAT_MODE_OFF
instead.@Deprecated static final int REPEAT_MODE_ONE
Player.REPEAT_MODE_ONE
instead.@Deprecated static final int REPEAT_MODE_ALL
Player.REPEAT_MODE_ALL
instead.android.os.Looper getPlaybackLooper()
Looper
associated with the playback thread.Looper
associated with the playback thread.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).void sendMessages(ExoPlayer.ExoPlayerMessage... messages)
ExoPlaybackException
then it is propagated out of the player
as an error.messages
- The messages to be sent.void blockingSendMessages(ExoPlayer.ExoPlayerMessage... messages)
sendMessages(ExoPlayerMessage...)
that blocks until after the messages have
been delivered.messages
- The messages to be sent.