interface ExoPlayer : 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

This interface is deprecated.

Use ExoPlayer, as all methods are defined by that interface.

A listener for audio offload events.

A builder for ExoPlayer instances.

This interface is deprecated.

Use Player, as all methods are defined by that interface.

This interface is deprecated.

Use Player, as all methods are defined by that interface.

This interface is deprecated.

Use ExoPlayer, as all methods are defined by that interface.

Constants

const Long

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

const Long

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

Public functions

Unit

Adds an AnalyticsListener to receive analytics events.

Unit

Adds a listener to receive audio offload events.

Unit

Adds a media source to the end of the playlist.

Unit
@UnstableApi
addMediaSource(index: Int, mediaSource: MediaSource!)

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

Unit

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

Unit
@UnstableApi
addMediaSources(index: Int, mediaSources: (Mutable)List<MediaSource!>!)

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

Unit

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

Unit

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

Unit

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

PlayerMessage!

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

AnalyticsCollector!

Returns the AnalyticsCollector used for collecting analytics events.

ExoPlayer.AudioComponent?

This function is deprecated.

Use ExoPlayer, as the AudioComponent methods are defined by that interface.

DecoderCounters?

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

Format?

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

Int

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

Clock!

Returns the Clock used for playback.

TrackGroupArray!

This function is deprecated.

Use getCurrentTracks.

TrackSelectionArray!

This function is deprecated.

Use getCurrentTracks.

ExoPlayer.DeviceComponent?

This function is deprecated.

Use Player, as the DeviceComponent methods are defined by that interface.

Boolean

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

Looper!

Returns the Looper associated with the playback thread.

ExoPlaybackException?

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

Renderer!

Returns the renderer at the given index.

Int

Returns the number of renderers.

Int

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

SeekParameters!

Returns the currently active SeekParameters of the player.

Boolean

Returns whether skipping silences in the audio stream is enabled.

ExoPlayer.TextComponent?

This function is deprecated.

Use Player, as the TextComponent methods are defined by that interface.

TrackSelector?

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

Int

Returns the C.VideoChangeFrameRateStrategy.

ExoPlayer.VideoComponent?

This function is deprecated.

Use ExoPlayer, as the VideoComponent methods are defined by that interface.

DecoderCounters?

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

Format?

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

Int

Returns the C.VideoScalingMode.

Boolean

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

Boolean

Returns whether tunneling is enabled for the currently selected tracks.

Unit

This function is deprecated.

Use setMediaSource and prepare instead.

Unit
@UnstableApi
prepare(
    mediaSource: MediaSource!,
    resetPosition: Boolean,
    resetState: Boolean
)

This function is deprecated.

Use setMediaSource and prepare instead.

Unit

Removes an AnalyticsListener.

Unit

Removes a listener of audio offload events.

Unit
replaceMediaItem(index: Int, mediaItem: MediaItem!)

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

Unit
replaceMediaItems(
    fromIndex: Int,
    toIndex: Int,
    mediaItems: (Mutable)List<MediaItem!>!
)

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

Unit

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

Unit

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

Unit

Sets a listener of camera motion events.

Unit

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

Unit
setHandleAudioBecomingNoisy(handleAudioBecomingNoisy: Boolean)

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

Unit

Sets the ImageOutput where rendered images will be forwarded.

Unit

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

Unit
@UnstableApi
setMediaSource(mediaSource: MediaSource!, resetPosition: Boolean)

Clears the playlist and adds the specified MediaSource.

Unit
@UnstableApi
setMediaSource(mediaSource: MediaSource!, startPositionMs: Long)

Clears the playlist and adds the specified MediaSource.

Unit

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

Unit
@UnstableApi
setMediaSources(
    mediaSources: (Mutable)List<MediaSource!>!,
    resetPosition: Boolean
)

Clears the playlist and adds the specified MediaSources.

Unit
@UnstableApi
setMediaSources(
    mediaSources: (Mutable)List<MediaSource!>!,
    startMediaItemIndex: Int,
    startPositionMs: Long
)

Clears the playlist and adds the specified MediaSources.

Unit

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

Unit

Sets the preferred audio device.

Unit

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

Unit

Sets the parameters that control how seek operations are performed.

Unit

Sets the shuffle order.

Unit

Sets whether skipping silences in the audio stream is enabled.

Unit

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

Unit
@RequiresApi(value = 18)
@UnstableApi
setVideoEffects(videoEffects: (Mutable)List<Effect!>!)

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

Unit

Sets a listener to receive video frame metadata events.

Unit

Sets the C.VideoScalingMode.

Unit

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

Inherited Constants

From androidx.media3.common.Player
const Int

This property is deprecated.

Use COMMAND_ADJUST_DEVICE_VOLUME_WITH_FLAGS instead.

const Int

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

const Int

Command to change the media items in the playlist.

const Int

Command to get the player current AudioAttributes.

const Int

Command to get information about the currently playing MediaItem.

const Int

Command to get the device volume and whether it is muted.

const Int

This property is deprecated.

Use COMMAND_GET_METADATA instead.

const Int

Command to get metadata related to the playlist and current MediaItem.

const Int

Command to get the text that should currently be displayed by the player.

const Int

Command to get the information about the current timeline.

const Int

Command to get details of the current track selection.

const Int

Command to get the player volume.

const Int

Represents an invalid Command.

const Int

Command to start, pause or resume playback.

const Int

Command to prepare the player.

const Int

Command to release the player.

const Int

Command to seek back by a fixed increment inside the current MediaItem.

const Int

Command to seek forward by a fixed increment inside the current MediaItem.

const Int

Command to seek anywhere inside the current MediaItem.

const Int

This property is deprecated.

Use COMMAND_SEEK_IN_CURRENT_MEDIA_ITEM instead.

const Int

Command to seek to the default position of the current MediaItem.

const Int

Command to seek anywhere in any MediaItem.

const Int

Command to seek to a later position in the current MediaItem or the default position of the next MediaItem.

const Int

Command to seek to the default position of the next MediaItem.

const Int

This property is deprecated.

Use COMMAND_SEEK_TO_NEXT_MEDIA_ITEM instead.

const Int

Command to seek to an earlier position in the current MediaItem or the default position of the previous MediaItem.

const Int

Command to seek to the default position of the previous MediaItem.

const Int

This property is deprecated.

Use COMMAND_SEEK_TO_PREVIOUS_MEDIA_ITEM instead.

const Int

This property is deprecated.

Use COMMAND_SEEK_TO_MEDIA_ITEM instead.

const Int

Command to set the player's audio attributes.

const Int

This property is deprecated.

Use COMMAND_SET_DEVICE_VOLUME_WITH_FLAGS instead.

const Int

Command to set the device volume with volume flags.

const Int

Command to set a MediaItem.

const Int

This property is deprecated.

Use COMMAND_SET_PLAYLIST_METADATA instead.

const Int

Command to set the playlist metadata.

const Int

Command to set the repeat mode.

const Int

Command to enable shuffling.

const Int

Command to set the playback speed and pitch.

const Int

Command to set the player's track selection parameters.

const Int

Command to set and clear the surface on which to render the video.

const Int

Command to set the player volume.

const Int

Command to stop playback.

const Int

Automatic playback transition from one period in the timeline to the next.

const Int

Discontinuity introduced internally (e.g. by the source).

const Int

Discontinuity caused by the removal of the current period from the Timeline.

const Int

Seek within the current period or to another period.

const Int

Seek adjustment due to being unable to seek to the requested position or because the seek was permitted to be inexact.

const Int

Discontinuity introduced by a skipped silence.

const Int

Discontinuity introduced by a skipped period (for instance a skipped ad).

const Int

getAudioAttributes changed.

const Int

The audio session id was set.

const Int

isCommandAvailable changed for at least one Command.

const Int

getCurrentCues changed.

const Int

getDeviceInfo changed.

const Int

getDeviceVolume changed.

const Int

isLoading ()} changed.

const Int

isPlaying changed.

const Int

getMaxSeekToPreviousPosition changed.

const Int

getCurrentMediaItem changed or the player started repeating the current item.

const Int

getMediaMetadata changed.

const Int

Metadata associated with the current playback time changed.

const Int

getPlaybackParameters changed.

const Int

getPlaybackState changed.

const Int

getPlaybackSuppressionReason changed.

const Int

getPlayerError changed.

const Int

getPlaylistMetadata changed.

const Int

getPlayWhenReady changed.

const Int

A position discontinuity occurred.

const Int

A frame is rendered for the first time since setting the surface, or since the renderer was reset, or since the stream being rendered was changed.

const Int

getRepeatMode changed.

const Int

getSeekBackIncrement changed.

const Int

getSeekForwardIncrement changed.

const Int

getShuffleModeEnabled changed.

const Int

Skipping silences in the audio stream is enabled or disabled.

const Int

The size of the surface onto which the video is being rendered changed.

const Int

getCurrentTimeline changed.

const Int

getCurrentTracks changed.

const Int

getTrackSelectionParameters changed.

const Int

getVideoSize changed.

const Int

getVolume changed.

const Int

Playback has automatically transitioned to the next media item.

const Int

The current media item has changed because of a change in the playlist.

const Int

The media item has been repeated.

const Int

A seek to another media item has occurred.

const Int

Playback is not suppressed.

const Int

Playback is suppressed due to transient audio focus loss.

const Int

Playback is suppressed due to attempt to play on an unsuitable audio output (e.g. attempt to play on built-in speaker on a Wear OS device).

const Int

This property is deprecated.

Use PLAYBACK_SUPPRESSION_REASON_UNSUITABLE_AUDIO_OUTPUT instead.

const Int

Playback has been paused to avoid becoming noisy.

const Int

Playback has been paused because of a loss of audio focus.

const Int

Playback has been paused at the end of a media item.

const Int

Playback has been started or paused because of a remote change.

const Int

Playback has been paused because playback has been suppressed too long.

const Int

Playback has been started or paused by a call to setPlayWhenReady.

const Int

Repeats the entire timeline infinitely.

const Int

Normal playback without repetition.

const Int

Repeats the currently playing MediaItem infinitely during ongoing playback.

const Int

The player is not able to immediately play the media, but is doing work toward being able to do so.

const Int

The player has finished playing the media.

const Int

The player is idle, meaning it holds only limited resources.

const Int

The player is able to immediately play from its current position.

const Int

Timeline changed as a result of a change of the playlist items or the order of the items.

const Int

Timeline changed as a result of a source update (e.g. result of a dynamic update by the played media).

Inherited functions

From androidx.media3.common.Player
Unit

Registers a listener to receive all events from the player.

Unit
addMediaItem(mediaItem: MediaItem!)

Adds a media item to the end of the playlist.

Unit
addMediaItem(index: Int, mediaItem: MediaItem!)

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

Unit

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

Unit
addMediaItems(index: Int, mediaItems: (Mutable)List<MediaItem!>!)

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

Boolean

Returns whether the player can be used to advertise a media session.

Unit

Clears the playlist.

Unit

Clears any Surface, SurfaceHolder, SurfaceView or TextureView currently set on the player.

Unit

Clears the Surface onto which video is being rendered if it matches the one passed.

Unit

Clears the SurfaceHolder that holds the Surface onto which video is being rendered if it matches the one passed.

Unit

Clears the SurfaceView onto which video is being rendered if it matches the one passed.

Unit

Clears the TextureView onto which video is being rendered if it matches the one passed.

Unit

This function is deprecated.

Use decreaseDeviceVolume instead.

Unit

Decreases the volume of the device.

Looper!

Returns the Looper associated with the application thread that's used to access the player and on which player events are received.

AudioAttributes!

Returns the attributes for audio playback.

Player.Commands!

Returns the player's currently available Commands.

@IntRange(from = 0, to = 100) Int

Returns an estimate of the percentage in the current content or ad up to which data is buffered, or 0 if no estimate is available.

Long

Returns an estimate of the position in the current content or ad up to which data is buffered, in milliseconds.

Long

If isPlayingAd returns true, returns an estimate of the content position in the current content up to which data is buffered, in milliseconds.

Long

If isPlayingAd returns true, returns the duration of the current content in milliseconds, or TIME_UNSET if the duration is not known.

Long

If isPlayingAd returns true, returns the content position that will be played once all ads in the ad group have finished playing, in milliseconds.

Int

If isPlayingAd returns true, returns the index of the ad group in the period currently being played.

Int

If isPlayingAd returns true, returns the index of the ad in its ad group.

CueGroup!

Returns the current CueGroup.

Long

Returns the offset of the current playback position from the live edge in milliseconds, or TIME_UNSET if the current MediaItemisn't live or the offset is unknown.

Any?

Returns the current manifest.

MediaItem?

Returns the currently playing MediaItem.

Int

Returns the index of the current MediaItem in the timeline, or the prospective index if the current timeline is empty.

Int

Returns the index of the period currently being played.

Long

Returns the playback position in the current content or ad, in milliseconds, or the prospective position in milliseconds if the current timeline is empty.

Timeline!

Returns the current Timeline.

Tracks!

Returns the current tracks.

Int

This function is deprecated.

Use getCurrentMediaItemIndex instead.

DeviceInfo!

Gets the device information.

@IntRange(from = 0) Int

Gets the current volume of the device.

Long

Returns the duration of the current content or ad in milliseconds, or TIME_UNSET if the duration is not known.

Long

Returns the maximum position for which seekToPrevious seeks to the previous , in milliseconds.

MediaItem!

Returns the MediaItem at the given index.

Int

Returns the number of media items in the playlist.

MediaMetadata!

Returns the current combined MediaMetadata, or EMPTY if not supported.

Int

Returns the index of the MediaItem that will be played if seekToNextMediaItem is called, which may depend on the current repeat mode and whether shuffle mode is enabled.

Int

This function is deprecated.

Use getNextMediaItemIndex instead.

Boolean

Whether playback will proceed when getPlaybackState == STATE_READY.

PlaybackParameters!

Returns the currently active playback parameters.

Int

Returns the current playback state of the player.

Int

Returns the reason why playback is suppressed even though getPlayWhenReady is true, or PLAYBACK_SUPPRESSION_REASON_NONE if playback is not suppressed.

MediaMetadata!

Returns the playlist MediaMetadata, as set by setPlaylistMetadata, or EMPTY if not supported.

Int

Returns the index of the MediaItem that will be played if seekToPreviousMediaItem is called, which may depend on the current repeat mode and whether shuffle mode is enabled.

Int

This function is deprecated.

Use getPreviousMediaItemIndex instead.

Int

Returns the current RepeatMode used for playback.

Long

Returns the seekBack increment.

Long

Returns the seekForward increment.

Boolean

Returns whether shuffling of media items is enabled.

Size!

Gets the size of the surface on which the video is rendered.

Long

Returns an estimate of the total buffered duration from the current position, in milliseconds.

TrackSelectionParameters!

Returns the parameters constraining the track selection.

VideoSize!

Gets the size of the video.

@FloatRange(from = 0, to = 1.0) Float

Returns the audio volume, with 0 being silence and 1 being unity gain (signal unchanged).

Boolean

This function is deprecated.

Use hasNextMediaItem instead.

Boolean

Returns whether a next MediaItem exists, which may depend on the current repeat mode and whether shuffle mode is enabled.

Boolean

This function is deprecated.

Use hasNextMediaItem instead.

Boolean

This function is deprecated.

Use hasPreviousMediaItem instead.

Boolean

Returns whether a previous media item exists, which may depend on the current repeat mode and whether shuffle mode is enabled.

Boolean

This function is deprecated.

Use hasPreviousMediaItem instead.

Unit

This function is deprecated.

Use increaseDeviceVolume instead.

Unit

Increases the volume of the device.

Boolean

Returns whether the provided Command is available.

Boolean

Returns whether the current MediaItem is dynamic (may change when the Timeline is updated), or false if the Timeline is empty.

Boolean

Returns whether the current MediaItem is live, or false if the Timeline is empty.

Boolean

Returns whether the current MediaItem is seekable, or false if the is empty.

Boolean

This function is deprecated.

Use isCurrentMediaItemDynamic instead.

Boolean

This function is deprecated.

Use isCurrentMediaItemLive instead.

Boolean

This function is deprecated.

Use isCurrentMediaItemSeekable instead.

Boolean

Gets whether the device is muted or not.

Boolean

Whether the player is currently loading the source.

Boolean

Returns whether the player is playing, i.e. getCurrentPosition is advancing.

Boolean

Returns whether the player is currently playing an ad.

Unit
moveMediaItem(currentIndex: Int, newIndex: Int)

Moves the media item at the current index to the new index.

Unit
moveMediaItems(fromIndex: Int, toIndex: Int, newIndex: Int)

Moves the media item range to the new index.

Unit

This function is deprecated.

Use seekToNextMediaItem instead.

Unit

Pauses playback.

Unit

Resumes playback as soon as getPlaybackState == STATE_READY.

Unit

Prepares the player.

Unit

This function is deprecated.

Use seekToPreviousMediaItem instead.

Unit

Releases the player.

Unit

Unregister a listener registered through addListener.

Unit

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

Unit
removeMediaItems(fromIndex: Int, toIndex: Int)

Removes a range of media items from the playlist.

Unit

Seeks back in the current MediaItem by getSeekBackIncrement milliseconds.

Unit

Seeks forward in the current MediaItem by getSeekForwardIncrement milliseconds.

Unit
seekTo(positionMs: Long)

Seeks to a position specified in milliseconds in the current MediaItem.

Unit
seekTo(mediaItemIndex: Int, positionMs: Long)

Seeks to a position specified in milliseconds in the specified MediaItem.

Unit

Seeks to the default position associated with the current MediaItem.

Unit
seekToDefaultPosition(mediaItemIndex: Int)

Seeks to the default position associated with the specified MediaItem.

Unit

Seeks to a later position in the current or next MediaItem (if available).

Unit

Seeks to the default position of the next MediaItem, which may depend on the current repeat mode and whether shuffle mode is enabled.

Unit

This function is deprecated.

Use seekToNextMediaItem instead.

Unit

Seeks to an earlier position in the current or previous MediaItem (if available).

Unit

Seeks to the default position of the previous MediaItem, which may depend on the current repeat mode and whether shuffle mode is enabled.

Unit

This function is deprecated.

Use seekToPreviousMediaItem instead.

Unit
setAudioAttributes(
    audioAttributes: AudioAttributes!,
    handleAudioFocus: Boolean
)

Sets the attributes for audio playback, used by the underlying audio track.

Unit

This function is deprecated.

Use setDeviceMuted instead.

Unit

Sets the mute state of the device.

Unit
setDeviceVolume(volume: @IntRange(from = 0) Int)

This function is deprecated.

Use setDeviceVolume instead.

Unit
setDeviceVolume(volume: @IntRange(from = 0) Int, @C.VolumeFlags flags: Int)

Sets the volume of the device with volume flags.

Unit
setMediaItem(mediaItem: MediaItem!)

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

Unit
setMediaItem(mediaItem: MediaItem!, resetPosition: Boolean)

Clears the playlist and adds the specified MediaItem.

Unit
setMediaItem(mediaItem: MediaItem!, startPositionMs: Long)

Clears the playlist and adds the specified MediaItem.

Unit

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

Unit
setMediaItems(
    mediaItems: (Mutable)List<MediaItem!>!,
    resetPosition: Boolean
)

Clears the playlist and adds the specified media items.

Unit
setMediaItems(
    mediaItems: (Mutable)List<MediaItem!>!,
    startIndex: Int,
    startPositionMs: Long
)

Clears the playlist and adds the specified media items.

Unit
setPlayWhenReady(playWhenReady: Boolean)

Sets whether playback should proceed when getPlaybackState == STATE_READY.

Unit

Attempts to set the playback parameters.

Unit
setPlaybackSpeed(speed: @FloatRange(from = 0, fromInclusive = false) Float)

Changes the rate at which playback occurs.

Unit

Sets the playlist MediaMetadata.

Unit

Sets the RepeatMode to be used for playback.

Unit
setShuffleModeEnabled(shuffleModeEnabled: Boolean)

Sets whether shuffling of media items is enabled.

Unit

Sets the parameters constraining the track selection.

Unit

Sets the Surface onto which video will be rendered.

Unit

Sets the SurfaceHolder that holds the Surface onto which video will be rendered.

Unit

Sets the SurfaceView onto which video will be rendered.

Unit

Sets the TextureView onto which video will be rendered.

Unit
setVolume(volume: @FloatRange(from = 0, to = 1.0) Float)

Sets the audio volume, valid values are between 0 (silence) and 1 (unity gain, signal unchanged), inclusive.

Unit

Stops playback without resetting the playlist.

Constants

DEFAULT_DETACH_SURFACE_TIMEOUT_MS

@UnstableApi
const val DEFAULT_DETACH_SURFACE_TIMEOUT_MS = 2000: Long

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

DEFAULT_RELEASE_TIMEOUT_MS

@UnstableApi
const val DEFAULT_RELEASE_TIMEOUT_MS = 500: Long

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

Public functions

addAnalyticsListener

fun addAnalyticsListener(listener: AnalyticsListener!): Unit

Adds an AnalyticsListener to receive analytics events.

This method can be called from any thread.

Parameters
listener: AnalyticsListener!

The listener to be added.

addAudioOffloadListener

@UnstableApi
fun addAudioOffloadListener(listener: ExoPlayer.AudioOffloadListener!): Unit

Adds a listener to receive audio offload events.

This method can be called from any thread.

Parameters
listener: ExoPlayer.AudioOffloadListener!

The listener to register.

addMediaSource

@UnstableApi
fun addMediaSource(mediaSource: MediaSource!): Unit

Adds a media source to the end of the playlist.

Parameters
mediaSource: MediaSource!

The MediaSource to add.

addMediaSource

@UnstableApi
fun addMediaSource(index: Int, mediaSource: MediaSource!): Unit

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

Parameters
index: Int

The index at which to add the source.

mediaSource: MediaSource!

The MediaSource to add.

addMediaSources

@UnstableApi
fun addMediaSources(mediaSources: (Mutable)List<MediaSource!>!): Unit

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

Parameters
mediaSources: (Mutable)List<MediaSource!>!

The MediaSources to add.

addMediaSources

@UnstableApi
fun addMediaSources(index: Int, mediaSources: (Mutable)List<MediaSource!>!): Unit

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

Parameters
index: Int

The index at which to add the media sources.

mediaSources: (Mutable)List<MediaSource!>!

The MediaSources to add.

clearAuxEffectInfo

@UnstableApi
fun clearAuxEffectInfo(): Unit

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

clearCameraMotionListener

@UnstableApi
fun clearCameraMotionListener(listener: CameraMotionListener!): Unit

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

Parameters
listener: CameraMotionListener!

The listener to clear.

clearVideoFrameMetadataListener

@UnstableApi
fun clearVideoFrameMetadataListener(listener: VideoFrameMetadataListener!): Unit

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

Parameters
listener: VideoFrameMetadataListener!

The listener to clear.

createMessage

@UnstableApi
fun createMessage(target: PlayerMessage.Target!): PlayerMessage!

Creates a message that can be sent to a PlayerMessage.Target. By default, the message will be delivered immediately without blocking on the playback thread. The default getType is 0 and the default getPayload is null. If a position is specified with setPosition, the message will be delivered at this position in the current media item defined by getCurrentMediaItemIndex. Alternatively, the message can be sent at a specific mediaItem using setPosition.

getAnalyticsCollector

@UnstableApi
fun getAnalyticsCollector(): AnalyticsCollector!

Returns the AnalyticsCollector used for collecting analytics events.

getAudioComponent

@UnstableApi
fun getAudioComponent(): ExoPlayer.AudioComponent?

getAudioDecoderCounters

@UnstableApi
fun getAudioDecoderCounters(): DecoderCounters?

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

getAudioFormat

@UnstableApi
fun getAudioFormat(): Format?

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

getAudioSessionId

@UnstableApi
fun getAudioSessionId(): Int

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

getClock

@UnstableApi
fun getClock(): Clock!

Returns the Clock used for playback.

This method can be called from any thread.

getCurrentTrackGroups

@UnstableApi
fun getCurrentTrackGroups(): TrackGroupArray!

Returns the available track groups.

See also
onTracksChanged

getCurrentTrackSelections

@UnstableApi
fun getCurrentTrackSelections(): TrackSelectionArray!

Returns the current track selections for each renderer, which may include null elements if some renderers do not have any selected tracks.

See also
onTracksChanged

getDeviceComponent

@UnstableApi
fun getDeviceComponent(): ExoPlayer.DeviceComponent?

getPauseAtEndOfMediaItems

@UnstableApi
fun getPauseAtEndOfMediaItems(): Boolean

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

getPlaybackLooper

@UnstableApi
fun getPlaybackLooper(): Looper!

Returns the Looper associated with the playback thread.

This method may be called from any thread.

getPlayerError

fun getPlayerError(): ExoPlaybackException?

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

getRenderer

@UnstableApi
fun getRenderer(index: Int): Renderer!

Returns the renderer at the given index.

Parameters
index: Int

The index of the renderer.

Returns
Renderer!

The renderer at this index.

getRendererCount

@UnstableApi
fun getRendererCount(): Int

Returns the number of renderers.

getRendererType

@UnstableApi
@C.TrackType
fun getRendererType(index: Int): Int

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

For example, a video renderer will return TRACK_TYPE_VIDEO, an audio renderer will return TRACK_TYPE_AUDIO and a text renderer will return TRACK_TYPE_TEXT.

Parameters
index: Int

The index of the renderer.

Returns
Int

The track type that the renderer handles.

getSeekParameters

@UnstableApi
fun getSeekParameters(): SeekParameters!

Returns the currently active SeekParameters of the player.

getSkipSilenceEnabled

@UnstableApi
fun getSkipSilenceEnabled(): Boolean

Returns whether skipping silences in the audio stream is enabled.

getTextComponent

@UnstableApi
fun getTextComponent(): ExoPlayer.TextComponent?

getTrackSelector

@UnstableApi
fun getTrackSelector(): TrackSelector?

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

getVideoComponent

@UnstableApi
fun getVideoComponent(): ExoPlayer.VideoComponent?

getVideoDecoderCounters

@UnstableApi
fun getVideoDecoderCounters(): DecoderCounters?

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

getVideoFormat

@UnstableApi
fun getVideoFormat(): Format?

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

getVideoScalingMode

@UnstableApi
@C.VideoScalingMode
fun getVideoScalingMode(): Int

Returns the C.VideoScalingMode.

isSleepingForOffload

@UnstableApi
fun isSleepingForOffload(): Boolean

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

Offload scheduling mode should save significant power when the phone is playing offload audio with the screen off.

Offload scheduling is only enabled when playing an audio track in offload mode, which requires all the following:

  • Audio offload rendering is enabled through setAudioOffloadPreferences.
  • An audio track is playing in a format that the device supports offloading (for example, MP3 or AAC).
  • The AudioSink is playing with an offload AudioTrack.

isTunnelingEnabled

@UnstableApi
fun isTunnelingEnabled(): Boolean

Returns whether tunneling is enabled for the currently selected tracks.

See also
onTracksChanged

prepare

@UnstableApi
fun prepare(mediaSource: MediaSource!): Unit

prepare

@UnstableApi
fun prepare(
    mediaSource: MediaSource!,
    resetPosition: Boolean,
    resetState: Boolean
): Unit

removeAnalyticsListener

fun removeAnalyticsListener(listener: AnalyticsListener!): Unit

Removes an AnalyticsListener.

Parameters
listener: AnalyticsListener!

The listener to be removed.

removeAudioOffloadListener

@UnstableApi
fun removeAudioOffloadListener(listener: ExoPlayer.AudioOffloadListener!): Unit

Removes a listener of audio offload events.

Parameters
listener: ExoPlayer.AudioOffloadListener!

The listener to unregister.

replaceMediaItem

fun replaceMediaItem(index: Int, mediaItem: MediaItem!): Unit

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

Implementations of this method may attempt to seamlessly continue playback if the currently playing media item is replaced with a compatible one (e.g. same URL, only metadata has changed).

This method must only be called if #COMMAND_CHANGE_MEDIA_ITEMS is * #getAvailableCommands() available.

ExoPlayer will keep the existing MediaSource for this MediaItem if supported by the MediaSource. If the current item is replaced, this will also not interrupt the ongoing playback.

replaceMediaItems

fun replaceMediaItems(
    fromIndex: Int,
    toIndex: Int,
    mediaItems: (Mutable)List<MediaItem!>!
): Unit

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

Implementations of this method may attempt to seamlessly continue playback if the currently playing media item is replaced with a compatible one (e.g. same URL, only metadata has changed).

This method must only be called if #COMMAND_CHANGE_MEDIA_ITEMS is * #getAvailableCommands() available.

Note that it is possible to replace a range with an arbitrary number of new items, so that the number of removed items defined by fromIndex} and toIndex} does not have to match the number of added items defined by mediaItems}. As result, it may also change the index of subsequent items not touched by this operation.

ExoPlayer will keep the existing MediaSource instances for the new MediaItems if supported by all of these instances. If the current item is replaced, this will also not interrupt the ongoing playback.

setAudioSessionId

@UnstableApi
fun setAudioSessionId(audioSessionId: Int): Unit

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

The audio session ID can be generated using generateAudioSessionIdV21 for API 21+.

Parameters
audioSessionId: Int

The audio session ID, or AUDIO_SESSION_ID_UNSET if it should be generated by the framework.

setAuxEffectInfo

@UnstableApi
fun setAuxEffectInfo(auxEffectInfo: AuxEffectInfo!): Unit

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

setCameraMotionListener

@UnstableApi
fun setCameraMotionListener(listener: CameraMotionListener!): Unit

Sets a listener of camera motion events.

Parameters
listener: CameraMotionListener!

The listener.

setForegroundMode

@UnstableApi
fun setForegroundMode(foregroundMode: Boolean): Unit

Sets whether the player is allowed to keep holding limited resources such as video decoders, even when in the idle state. By doing so, the player may be able to reduce latency when starting to play another piece of content for which the same resources are required.

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:

  • The application that owns the player is in the foreground.
  • The player is used in a way that may benefit from foreground mode. For this to be true, the same player instance must be used to play multiple pieces of content, and there must be gaps between the playbacks (i.e. stop is called to halt one playback, and prepare 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 stop does not need to be called, and simply calling prepare 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.

Parameters
foregroundMode: Boolean

Whether the player is allowed to keep limited resources even when in the idle state.

setHandleAudioBecomingNoisy

fun setHandleAudioBecomingNoisy(handleAudioBecomingNoisy: Boolean): Unit

Sets whether the player should pause automatically when audio is rerouted from a headset to device speakers. See the audio becoming noisy documentation for more information.

Parameters
handleAudioBecomingNoisy: Boolean

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

setImageOutput

@UnstableApi
fun setImageOutput(imageOutput: ImageOutput!): Unit

Sets the ImageOutput where rendered images will be forwarded.

Parameters
imageOutput: ImageOutput!

The ImageOutput.

setMediaSource

@UnstableApi
fun setMediaSource(mediaSource: MediaSource!): Unit

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

Parameters
mediaSource: MediaSource!

The new MediaSource.

setMediaSource

@UnstableApi
fun setMediaSource(mediaSource: MediaSource!, resetPosition: Boolean): Unit

Clears the playlist and adds the specified MediaSource.

Parameters
mediaSource: MediaSource!

The new MediaSource.

resetPosition: Boolean

Whether the playback position should be reset to the default position. If false, playback will start from the position defined by getCurrentMediaItemIndex and getCurrentPosition.

setMediaSource

@UnstableApi
fun setMediaSource(mediaSource: MediaSource!, startPositionMs: Long): Unit

Clears the playlist and adds the specified MediaSource.

Parameters
mediaSource: MediaSource!

The new MediaSource.

startPositionMs: Long

The position in milliseconds to start playback from. If TIME_UNSET is passed, the default position of the given media source is used.

setMediaSources

@UnstableApi
fun setMediaSources(mediaSources: (Mutable)List<MediaSource!>!): Unit

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

Parameters
mediaSources: (Mutable)List<MediaSource!>!

The new MediaSources.

setMediaSources

@UnstableApi
fun setMediaSources(
    mediaSources: (Mutable)List<MediaSource!>!,
    resetPosition: Boolean
): Unit

Clears the playlist and adds the specified MediaSources.

Parameters
mediaSources: (Mutable)List<MediaSource!>!

The new MediaSources.

resetPosition: Boolean

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 getCurrentMediaItemIndex and getCurrentPosition.

setMediaSources

@UnstableApi
fun setMediaSources(
    mediaSources: (Mutable)List<MediaSource!>!,
    startMediaItemIndex: Int,
    startPositionMs: Long
): Unit

Clears the playlist and adds the specified MediaSources.

Parameters
mediaSources: (Mutable)List<MediaSource!>!

The new MediaSources.

startMediaItemIndex: Int

The media item index to start playback from. If INDEX_UNSET is passed, the current position is not reset.

startPositionMs: Long

The position in milliseconds to start playback from. If TIME_UNSET is passed, the default position of the given media source is used. In any case, if startMediaItemIndex is set to INDEX_UNSET, this parameter is ignored and the position is not reset at all.

setPauseAtEndOfMediaItems

@UnstableApi
fun setPauseAtEndOfMediaItems(pauseAtEndOfMediaItems: Boolean): Unit

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

This means the player will pause at the end of each window in the current timeline. Listeners will be informed by a call to onPlayWhenReadyChanged with the reason PLAY_WHEN_READY_CHANGE_REASON_END_OF_MEDIA_ITEM when this happens.

Parameters
pauseAtEndOfMediaItems: Boolean

Whether to pause playback at the end of each media item.

setPreferredAudioDevice

@UnstableApi
@RequiresApi(value = 23)
fun setPreferredAudioDevice(audioDeviceInfo: AudioDeviceInfo?): Unit

Sets the preferred audio device.

Parameters
audioDeviceInfo: AudioDeviceInfo?

The preferred audio device, or null to restore the default.

setPriorityTaskManager

@UnstableApi
fun setPriorityTaskManager(priorityTaskManager: PriorityTaskManager?): Unit

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

The priority PRIORITY_PLAYBACK will be set while the player is loading.

Parameters
priorityTaskManager: PriorityTaskManager?

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

setSeekParameters

@UnstableApi
fun setSeekParameters(seekParameters: SeekParameters?): Unit

Sets the parameters that control how seek operations are performed.

Parameters
seekParameters: SeekParameters?

The seek parameters, or null to use the defaults.

setShuffleOrder

@UnstableApi
fun setShuffleOrder(shuffleOrder: ShuffleOrder!): Unit

Sets the shuffle order.

The ShuffleOrder passed must have the same length as the current playlist (getMediaItemCount).

Parameters
shuffleOrder: ShuffleOrder!

The shuffle order.

setSkipSilenceEnabled

@UnstableApi
fun setSkipSilenceEnabled(skipSilenceEnabled: Boolean): Unit

Sets whether skipping silences in the audio stream is enabled.

Parameters
skipSilenceEnabled: Boolean

Whether skipping silences in the audio stream is enabled.

setVideoChangeFrameRateStrategy

@UnstableApi
fun setVideoChangeFrameRateStrategy(
    @C.VideoChangeFrameRateStrategy videoChangeFrameRateStrategy: Int
): Unit

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

The strategy only applies if a MediaCodec-based video Renderer is enabled. Applications wishing to use CHANGE_FRAME_RATE_ALWAYS should set the mode to VIDEO_CHANGE_FRAME_RATE_STRATEGY_OFF to disable calls to setFrameRate from ExoPlayer, and should then call setFrameRate directly from application code.

Parameters
@C.VideoChangeFrameRateStrategy videoChangeFrameRateStrategy: Int

A C.VideoChangeFrameRateStrategy.

setVideoEffects

@RequiresApi(value = 18)
@UnstableApi
fun setVideoEffects(videoEffects: (Mutable)List<Effect!>!): Unit

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

If passing a surface to the player directly, the output resolution needs to be signaled by passing a renderer message with type MSG_SET_VIDEO_OUTPUT_RESOLUTION after calling this method. For SurfaceView, TextureView and SurfaceHolder output this happens automatically.

The following limitations exist for using video effects:

  • The androidx.media3:media3-effect module must be available on the runtime classpath. androidx.media3:media3-exoplayer does not explicitly depend on the effect module, so apps must make sure it's available themselves. It must be the same version as the rest of the androidx.media3 modules being used by the app.
  • This feature works only with the default MediaCodecVideoRenderer and not custom or extension video renderers.
  • This feature does not work with effects updating the timestamps.
  • This feature does not work with DRM-protected content.
  • This method should be called before calling prepare.
Parameters
videoEffects: (Mutable)List<Effect!>!

The List of video effects to apply.

setVideoFrameMetadataListener

@UnstableApi
fun setVideoFrameMetadataListener(listener: VideoFrameMetadataListener!): Unit

Sets a listener to receive video frame metadata events.

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.

Parameters
listener: VideoFrameMetadataListener!

The listener.

setVideoScalingMode

@UnstableApi
fun setVideoScalingMode(@C.VideoScalingMode videoScalingMode: Int): Unit

Sets the C.VideoScalingMode.

The scaling mode only applies if a MediaCodec-based video Renderer is enabled and if the output surface is owned by a SurfaceView.

Parameters
@C.VideoScalingMode videoScalingMode: Int

The C.VideoScalingMode.

setWakeMode

fun setWakeMode(@C.WakeMode wakeMode: Int): Unit

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

Enabling this feature requires the WAKE_LOCK permission. It should be used together with a foreground android.app.Service for use cases where playback occurs and the screen is off (e.g. background audio playback). It is not useful when the screen will be kept on during playback (e.g. foreground video playback).

When enabled, the locks (android.os.PowerManager.WakeLock / ) will be held whenever the player is in the STATE_READY or STATE_BUFFERING states with playWhenReady = true. The locks held depends on the specified C.WakeMode.

Parameters
@C.WakeMode wakeMode: Int

The C.WakeMode option to keep the device awake during playback.