public interface ExoPlayer extends Player

Known direct subclasses
SimpleExoPlayer

This class is deprecated.

Use ExoPlayer instead.

StubExoPlayer

An abstract ExoPlayer implementation that throws UnsupportedOperationException from every method.


An extensible media player that plays MediaSources. Instances can be obtained from .

Player components

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:

  • MediaSources that define the media to be played, load the media, and from which the loaded media can be read. MediaSources are created from MediaItems by the MediaSource.Factory injected into the player Builder, or can be added directly by methods like setMediaSource. The library provides a DefaultMediaSourceFactory for progressive media files, DASH, SmoothStreaming and HLS, which also includes functionality for side-loading subtitle files and clipping media.
  • 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. The number of renderers and their respective track types can be obtained by calling getRendererCount and getRendererType.
  • A 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.
  • A LoadControl that controls when the MediaSource buffers more media, and how much media is buffered. The library provides a default implementation () 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.

Threading model

The figure below shows ExoPlayer's threading model.

ExoPlayer's threading model

  • ExoPlayer instances must be accessed from a single application thread unless indicated otherwise. For the vast majority of cases this should be the application's main thread. Using the application's main thread is also a requirement when using ExoPlayer's UI components or the IMA extension. The thread on which an ExoPlayer instance must be accessed can be explicitly specified by passing a Looper when creating the player. If no Looper is specified, then the Looper of the thread that the player is created on is used, or if that thread does not have a Looper, the Looper of the application's main thread is used. In all cases the Looper of the thread from which the player must be accessed can be queried using getApplicationLooper.
  • Registered listeners are called on the thread associated with getApplicationLooper. Note that this means registered listeners are called on the same thread which must be used to access the player.
  • An internal playback thread is responsible for playback. Injected player components such as Renderers, MediaSources, TrackSelectors and LoadControls are called by the player on this thread.
  • When the application performs an operation on the player, for example a seek, a message is delivered to the internal playback thread via a message queue. The internal playback thread consumes messages from the queue and performs the corresponding operations. Similarly, when a playback event occurs on the internal playback thread, a message is delivered to the application thread via a second message queue. The application thread consumes messages from the queue, updating the application visible state and calling corresponding listener methods.
  • Injected player components may use additional background threads. For example a MediaSource may use background threads to load data. These are implementation specific.

Summary

Nested types

A listener for audio offload events.

public final class ExoPlayer.Builder

A builder for ExoPlayer instances.

Configuration options for preloading playlist items.

Constants

default static final long

The default timeout for detaching a surface from the player, in milliseconds.

default static final long

The default timeout for calls to release and setForegroundMode, in milliseconds.

Public methods

abstract void

Adds an AnalyticsListener to receive analytics events.

abstract void

Adds a listener to receive audio offload events.

abstract void

Adds a media source to the end of the playlist.

abstract void
@UnstableApi
addMediaSource(int index, MediaSource mediaSource)

Adds a media source at the given index of the playlist.

abstract void

Adds a list of media sources to the end of the playlist.

abstract void
@UnstableApi
addMediaSources(int index, List<MediaSource> mediaSources)

Adds a list of media sources at the given index of the playlist.

abstract void

Detaches any previously attached auxiliary audio effect from the underlying audio track.

abstract void

Clears the listener which receives camera motion events if it matches the one passed.

abstract void

Clears the listener which receives video frame metadata events if it matches the one passed.

abstract PlayerMessage

Creates a message that can be sent to a PlayerMessage.Target.

abstract AnalyticsCollector

Returns the AnalyticsCollector used for collecting analytics events.

abstract @Nullable DecoderCounters

Returns DecoderCounters for audio, or null if no audio is being played.

abstract @Nullable Format

Returns the audio format currently being played, or null if no audio is being played.

abstract int

Returns the audio session identifier, or AUDIO_SESSION_ID_UNSET if not set.

abstract Clock

Returns the Clock used for playback.

abstract TrackGroupArray

This method is deprecated.

Use getCurrentTracks.

abstract TrackSelectionArray

This method is deprecated.

Use getCurrentTracks.

abstract boolean

Returns whether the player pauses playback at the end of each media item.

abstract Looper

Returns the Looper associated with the playback thread.

abstract @Nullable ExoPlaybackException

Equivalent to getPlayerError, except the exception is guaranteed to be an ExoPlaybackException.

abstract ExoPlayer.PreloadConfiguration

Returns the preload configuration.

abstract Renderer

Returns the renderer at the given index.

abstract int

Returns the number of renderers.

abstract int

Returns the track type that the renderer at a given index handles.

abstract ScrubbingModeParameters

Gets the parameters that control behavior in scrubbing mode.

default @Nullable Renderer

Returns the secondary renderer at the given index.

abstract SeekParameters

Returns the currently active SeekParameters of the player.

abstract boolean

Returns whether skipping silences in the audio stream is enabled.

abstract @Nullable TrackSelector

Returns the track selector that this player uses, or null if track selection is not supported.

abstract int

Returns the C.VideoChangeFrameRateStrategy.

abstract @Nullable DecoderCounters

Returns DecoderCounters for video, or null if no video is being played.

abstract @Nullable Format

Returns the video format currently being played, or null if no video is being played.

abstract int

Returns the C.VideoScalingMode.

abstract boolean

Returns whether release has been called on the player.

abstract boolean

Returns whether the player is optimized for scrubbing (many frequent seeks).

abstract boolean

Returns whether the player has paused its main loop to save power in offload scheduling mode.

abstract boolean

Returns whether tunneling is enabled for the currently selected tracks.

abstract void

This method is deprecated.

Use setMediaSource and prepare instead.

abstract void
@UnstableApi
prepare(
    MediaSource mediaSource,
    boolean resetPosition,
    boolean resetState
)

This method is deprecated.

Use setMediaSource and prepare instead.

abstract void

Releases the player.

abstract void

Removes an AnalyticsListener.

abstract void

Removes a listener of audio offload events.

abstract void
replaceMediaItem(int index, MediaItem mediaItem)

Replaces the media item at the given index of the playlist.

abstract void
replaceMediaItems(
    int fromIndex,
    int toIndex,
    List<MediaItem> mediaItems
)

Replaces the media items at the given range of the playlist.

abstract void
@UnstableApi
setAudioSessionId(int audioSessionId)

Sets the ID of the audio session to attach to the underlying android.media.AudioTrack.

abstract void

Sets information on an auxiliary audio effect to attach to the underlying audio track.

abstract void

Sets a listener of camera motion events.

abstract void
@UnstableApi
setForegroundMode(boolean foregroundMode)

Sets whether the player is allowed to keep holding limited resources such as video decoders, even when in the idle state.

abstract void
setHandleAudioBecomingNoisy(boolean handleAudioBecomingNoisy)

Sets whether the player should pause automatically when audio is rerouted from a headset to device speakers.

abstract void

Sets the ImageOutput where rendered images will be forwarded.

abstract void

Clears the playlist, adds the specified MediaSource and resets the position to the default position.

abstract void
@UnstableApi
setMediaSource(MediaSource mediaSource, boolean resetPosition)

Clears the playlist and adds the specified MediaSource.

abstract void
@UnstableApi
setMediaSource(MediaSource mediaSource, long startPositionMs)

Clears the playlist and adds the specified MediaSource.

abstract void

Clears the playlist, adds the specified MediaSources and resets the position to the default position.

abstract void
@UnstableApi
setMediaSources(List<MediaSource> mediaSources, boolean resetPosition)

Clears the playlist and adds the specified MediaSources.

abstract void
@UnstableApi
setMediaSources(
    List<MediaSource> mediaSources,
    int startMediaItemIndex,
    long startPositionMs
)

Clears the playlist and adds the specified MediaSources.

abstract void
@UnstableApi
setPauseAtEndOfMediaItems(boolean pauseAtEndOfMediaItems)

Sets whether to pause playback at the end of each media item.

abstract void

Sets the preferred audio device.

abstract void

Sets the preload configuration to configure playlist preloading.

abstract void

Sets the C.Priority for this player.

abstract void

Sets a PriorityTaskManager, or null to clear a previously set priority task manager.

abstract void
@UnstableApi
setScrubbingModeEnabled(boolean scrubbingModeEnabled)

Sets whether to optimize the player for scrubbing (many frequent seeks).

abstract void

Sets the parameters that control behavior in scrubbing mode.

abstract void

Sets the parameters that control how seek operations are performed.

abstract void

Sets the shuffle order.

abstract void
@UnstableApi
setSkipSilenceEnabled(boolean skipSilenceEnabled)

Sets whether skipping silences in the audio stream is enabled.

abstract void

Sets a C.VideoChangeFrameRateStrategy that will be used by the player when provided with a video output Surface.

abstract void

Sets a List of video effects that will be applied to each video frame.

abstract void

Sets a listener to receive video frame metadata events.

abstract void

Sets the C.VideoScalingMode.

abstract void
setWakeMode(@C.WakeMode int wakeMode)

Sets how the player should keep the device awake for playback when the screen is off.

Inherited Constants

From androidx.media3.common.Player
default static final int

This field is deprecated.

Use COMMAND_ADJUST_DEVICE_VOLUME_WITH_FLAGS instead.

default static final int

Command to increase and decrease the device volume and mute it with volume flags.

default static final int

Command to change the media items in the playlist.

default static final int

Command to get the player current