public interface ExoPlayer extends Player
MediaSources. Instances can be obtained from
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:
MediaSourcethat 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 progressive media files (
ProgressiveMediaSource), 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 (
Renderers that render individual components of the media. The library provides default implementations for common media types (
MetadataRenderer). A Renderer consumes media from the MediaSource being played. Renderers are injected when the player is created.
TrackSelectorthat 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.
LoadControlthat 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(). 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|
A builder for
Player.AudioComponent, Player.DefaultEventListener, Player.DiscontinuityReason, Player.EventListener, Player.MetadataComponent, Player.PlaybackSuppressionReason, Player.RepeatMode, Player.State, Player.TextComponent, Player.TimelineChangeReason, Player.VideoComponent
DISCONTINUITY_REASON_AD_INSERTION, DISCONTINUITY_REASON_INTERNAL, DISCONTINUITY_REASON_PERIOD_TRANSITION, DISCONTINUITY_REASON_SEEK, DISCONTINUITY_REASON_SEEK_ADJUSTMENT, PLAYBACK_SUPPRESSION_REASON_NONE, PLAYBACK_SUPPRESSION_REASON_TRANSIENT_AUDIO_FOCUS_LOSS, REPEAT_MODE_ALL, REPEAT_MODE_OFF, REPEAT_MODE_ONE, STATE_BUFFERING, STATE_ENDED, STATE_IDLE, STATE_READY, TIMELINE_CHANGE_REASON_DYNAMIC, TIMELINE_CHANGE_REASON_PREPARED, TIMELINE_CHANGE_REASON_RESET
|Modifier and Type||Method and Description|
Creates a message that can be sent to a
Returns the currently active
Prepares the player to play the provided
Retries a failed or stopped playback.
Sets whether the player is allowed to keep holding limited resources such as video decoders, even when in the idle state.
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, getPlaybackSuppressionReason, getPlayWhenReady, getPreviousWindowIndex, getRendererCount, getRendererType, getRepeatMode, getShuffleModeEnabled, getTextComponent, getTotalBufferedDuration, getVideoComponent, hasNext, hasPrevious, isCurrentWindowDynamic, isCurrentWindowLive, isCurrentWindowSeekable, isLoading, isPlaying, isPlayingAd, next, previous, release, removeListener, seekTo, seekTo, seekToDefaultPosition, seekToDefaultPosition, setPlaybackParameters, setPlayWhenReady, setRepeatMode, setShuffleModeEnabled, stop, stop
Looperassociated with the playback thread.
void prepare(MediaSource mediaSource)
MediaSource. Equivalent to
prepare(mediaSource, true, true).
void prepare(MediaSource mediaSource, boolean resetPosition, boolean resetState)
MediaSource, optionally resetting the playback position the default position in the first
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
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
void setSeekParameters(@Nullable SeekParameters seekParameters)
seekParameters- The seek parameters, or
nullto use the defaults.
SeekParametersof the player.
void setForegroundMode(boolean foregroundMode)
This mode should be used with caution, since holding limited resources may prevent other players of media components from acquiring them. It should only be enabled when both of the following conditions are true:
Player.stop()is called to halt one playback, and
prepare(com.google.android.exoplayer2.source.MediaSource)is called some time later to start a new one).
Note that foreground mode is not useful for switching between content without gaps
between the playbacks. For this use case
Player.stop() does not need to be called, and simply
prepare(com.google.android.exoplayer2.source.MediaSource) for the new media will cause limited resources to be retained even if
foreground mode is not enabled.
If foreground mode is enabled, it's the application's responsibility to disable it when the conditions described above no longer hold.
foregroundMode- Whether the player is allowed to keep limited resources even when in the idle state.