@UnstableApi
public class StubExoPlayer extends StubPlayer implements ExoPlayer


An abstract ExoPlayer implementation that throws UnsupportedOperationException from every method.

Summary

Public constructors

Public methods

void

Adds an AnalyticsListener to receive analytics events.

void

Adds a listener to receive audio offload events.

void

Adds a media source to the end of the playlist.

void
addMediaSource(int index, MediaSource mediaSource)

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

void

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

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

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

void

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

void

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

void

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 method is deprecated.

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

@Nullable DecoderCounters

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

@Nullable 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 method is deprecated.

Use getCurrentTracks.

TrackSelectionArray

This method is deprecated.

Use getCurrentTracks.

ExoPlayer.DeviceComponent

This method 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

Returns the error that caused playback to fail.

Renderer
getRenderer(int index)

Returns the renderer at the given index.

int

Returns the number of renderers.

int
getRendererType(int index)

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 method is deprecated.

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

@Nullable 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 method is deprecated.

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

@Nullable DecoderCounters

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

@Nullable 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.

void
prepare(MediaSource mediaSource)

This method is deprecated.

Use setMediaSource and prepare instead.

void
prepare(
    MediaSource mediaSource,
    boolean resetPosition,
    boolean resetState
)

This method is deprecated.

Use setMediaSource and prepare instead.

void

Removes an AnalyticsListener.

void

Removes a listener of audio offload events.

void
setAudioAttributes(
    AudioAttributes audioAttributes,
    boolean handleAudioFocus
)

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

void
setAudioSessionId(int audioSessionId)

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

void

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

void

Sets a listener of camera motion events.

void
setForegroundMode(boolean foregroundMode)

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

void
setHandleAudioBecomingNoisy(boolean handleAudioBecomingNoisy)

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

void

Sets the ImageOutput where rendered images will be forwarded.

void

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

void
setMediaSource(MediaSource mediaSource, boolean resetPosition)

Clears the playlist and adds the specified MediaSource.

void
setMediaSource(MediaSource mediaSource, long startPositionMs)

Clears the playlist and adds the specified MediaSource.

void

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

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

Clears the playlist and adds the specified MediaSources.

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

Clears the playlist and adds the specified MediaSources.

void
setPauseAtEndOfMediaItems(boolean pauseAtEndOfMediaItems)

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

void

Sets the preferred audio device.

void
setPriorityTaskManager(
    @Nullable PriorityTaskManager priorityTaskManager
)

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

void

Sets the parameters that control how seek operations are performed.

void

Sets the shuffle order.

void
setSkipSilenceEnabled(boolean skipSilenceEnabled)

Sets whether skipping silences in the audio stream is enabled.

void
setVideoChangeFrameRateStrategy(int videoChangeFrameRateStrategy)

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

void
setVideoEffects(List<Effect> videoEffects)

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

void

Sets a listener to receive video frame metadata events.

void
setVideoScalingMode(int videoScalingMode)

Sets the C.VideoScalingMode.

void
setWakeMode(int wakeMode)

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

Inherited Constants

From androidx.media3.exoplayer.ExoPlayer
static final long

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

static final long

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

From androidx.media3.common.Player
static final int

This field is deprecated.

Use COMMAND_ADJUST_DEVICE_VOLUME_WITH_FLAGS instead.

static final int

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

static final int

Command to change the media items in the playlist.

static final int

Command to get the player current AudioAttributes.

static final int

Command to get information about the currently playing MediaItem.

static final int

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

static final int

This field is deprecated.

Use COMMAND_GET_METADATA instead.

static final int

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

static final int

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

static final int

Command to get the information about the current timeline.

static final int

Command to get details of the current track selection.

static final int

Command to get the player volume.

static final int

Represents an invalid Command.

static final int

Command to start, pause or resume playback.

static final int

Command to prepare the player.

static final int

Command to release the player.

static final int

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

static final int

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

static final int

Command to seek anywhere inside the current MediaItem.

static final int

This field is deprecated.

Use COMMAND_SEEK_IN_CURRENT_MEDIA_ITEM instead.

static final int

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

static final int

Command to seek anywhere in any MediaItem.

static final int

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

static final int

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

static final int

This field is deprecated.

Use COMMAND_SEEK_TO_NEXT_MEDIA_ITEM instead.

static final int

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

static final int

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

static final int

This field is deprecated.

Use COMMAND_SEEK_TO_PREVIOUS_MEDIA_ITEM instead.

static final int

This field is deprecated.

Use COMMAND_SEEK_TO_MEDIA_ITEM instead.

static final int

Command to set the player's audio attributes.

static final int

This field is deprecated.

Use COMMAND_SET_DEVICE_VOLUME_WITH_FLAGS instead.

static final int

Command to set the device volume with volume flags.

static final int

Command to set a MediaItem.

static final int

This field is deprecated.

Use COMMAND_SET_PLAYLIST_METADATA instead.

static final int

Command to set the playlist metadata.

static final int

Command to set the repeat mode.

static final int

Command to enable shuffling.

static final int

Command to set the playback speed and pitch.

static final int

Command to set the player's track selection parameters.

static final int

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

static final int

Command to set the player volume.

static final int

Command to stop playback.

static final int

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

static final int

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

static final int

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

static final int

Seek within the current period or to another period.

static final int

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

static final int

Discontinuity introduced by a skipped silence.

static final int

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

static final int

getAudioAttributes changed.

static final int

The audio session id was set.

static final int

isCommandAvailable changed for at least one Command.

static final int

getCurrentCues changed.

static final int

getDeviceInfo changed.

static final int

getDeviceVolume changed.

static final int

isLoading ()} changed.

static final int

isPlaying changed.

static final int

getMaxSeekToPreviousPosition changed.

static final int

getCurrentMediaItem changed or the player started repeating the current item.

static final int

getMediaMetadata changed.

static final int

Metadata associated with the current playback time changed.

static final int

getPlaybackParameters changed.

static final int

getPlaybackState changed.

static final int

getPlaybackSuppressionReason changed.

static final int

getPlayerError changed.

static final int

getPlaylistMetadata changed.

static final int

getPlayWhenReady changed.

static final int

A position discontinuity occurred.

static final 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.

static final int

getRepeatMode changed.

static final int

getSeekBackIncrement changed.

static final int

getSeekForwardIncrement changed.

static final int

getShuffleModeEnabled changed.

static final int

Skipping silences in the audio stream is enabled or disabled.

static final int

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

static final int

getCurrentTimeline changed.

static final int

getCurrentTracks changed.

static final int

getTrackSelectionParameters changed.

static final int

getVideoSize changed.

static final int

getVolume changed.

static final int

Playback has automatically transitioned to the next media item.

static final int

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

static final int

The media item has been repeated.

static final int

A seek to another media item has occurred.

static final int

Playback is not suppressed.

static final int

Playback is suppressed due to transient audio focus loss.

static final 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).

static final int

This field is deprecated.

Use PLAYBACK_SUPPRESSION_REASON_UNSUITABLE_AUDIO_OUTPUT instead.

static final int

Playback has been paused to avoid becoming noisy.

static final int

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

static final int

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

static final int

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

static final int

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

static final int

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

static final int

Repeats the entire timeline infinitely.

static final int

Normal playback without repetition.

static final int

Repeats the currently playing MediaItem infinitely during ongoing playback.

static final int

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

static final int

The player has finished playing the media.

static final int

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

static final int

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

static final int

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

static final int

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

Inherited methods

From androidx.media3.common.BasePlayer
final void

Adds a media item to the end of the playlist.

final void
addMediaItem(int index, MediaItem mediaItem)

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

final void

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

final boolean

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

final void

Clears the playlist.

final 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.

final long

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

final 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.

final @Nullable Object

Returns the current manifest.

final @Nullable MediaItem

Returns the currently playing MediaItem.

final int

This method is deprecated.

Use getCurrentMediaItemIndex instead.

final MediaItem
getMediaItemAt(int index)

Returns the MediaItem at the given index.

final int

Returns the number of media items in the playlist.

final 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.

final int

This method is deprecated.

Use getNextMediaItemIndex instead.

final 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.

final int

This method is deprecated.

Use getPreviousMediaItemIndex instead.

final boolean

This method is deprecated.

Use hasNextMediaItem instead.

final boolean

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

final boolean

This method is deprecated.

Use hasNextMediaItem instead.

final boolean

This method is deprecated.

Use hasPreviousMediaItem instead.

final boolean

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

final boolean

This method is deprecated.

Use hasPreviousMediaItem instead.

final boolean

Returns whether the provided Command is available.

final boolean

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

final boolean

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

final boolean

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

final boolean

This method is deprecated.

Use isCurrentMediaItemDynamic instead.

final boolean

This method is deprecated.

Use isCurrentMediaItemLive instead.

final boolean

This method is deprecated.

Use isCurrentMediaItemSeekable instead.

final boolean

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

final void
moveMediaItem(int currentIndex, int newIndex)

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

final void

This method is deprecated.

Use seekToNextMediaItem instead.

final void

Pauses playback.

final void

Resumes playback as soon as getPlaybackState == STATE_READY.

final void

This method is deprecated.

Use seekToPreviousMediaItem instead.

final void
removeMediaItem(int index)

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

final void

Seeks back in the current MediaItem by getSeekBackIncrement milliseconds.

final void

Seeks forward in the current MediaItem by getSeekForwardIncrement milliseconds.

final void
seekTo(long positionMs)

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

final void
seekTo(int mediaItemIndex, long positionMs)

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

final void

Seeks to the default position associated with the current MediaItem.

final void
seekToDefaultPosition(int mediaItemIndex)

Seeks to the default position associated with the specified MediaItem.

final void

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

final void

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

final void

This method is deprecated.

Use seekToNextMediaItem instead.

final void

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

final void

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

final void

This method is deprecated.

Use seekToPreviousMediaItem instead.

final void

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

final void
setMediaItem(MediaItem mediaItem, boolean resetPosition)

Clears the playlist and adds the specified MediaItem.

final void
setMediaItem(MediaItem mediaItem, long startPositionMs)

Clears the playlist and adds the specified MediaItem.

final void

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

final void
setPlaybackSpeed(float speed)

Changes the rate at which playback occurs.

From androidx.media3.exoplayer.ExoPlayer
abstract void
replaceMediaItem(int index, MediaItem mediaItem)

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

From androidx.media3.common.Player
abstract void
setDeviceVolume(@IntRange(from = 0) int volume)

This method is deprecated.

Use setDeviceVolume instead.

abstract void
setDeviceVolume(@IntRange(from = 0) int volume, @C.VolumeFlags int flags)

Sets the volume of the device with volume flags.

abstract void
setPlaybackSpeed(@FloatRange(from = 0, fromInclusive = false) float speed)

Changes the rate at which playback occurs.

abstract void
setVolume(@FloatRange(from = 0, to = 1.0) float volume)

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

From androidx.media3.test.utils.StubPlayer
void

Registers a listener to receive all events from the player.

void
addMediaItems(int index, List<MediaItem> mediaItems)

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

void

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

void

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

void

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

void

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

void

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

void

This method is deprecated.

Use decreaseDeviceVolume instead.

void

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.

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 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.

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.

DeviceInfo

Gets the device information.

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.

MediaMetadata

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

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 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.

float

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

void

This method is deprecated.

Use increaseDeviceVolume instead.

void

Increases the volume of the device.

boolean

Gets whether the device is muted or not.

boolean

Whether the player is currently loading the source.

boolean

Returns whether the player is currently playing an ad.

void
moveMediaItems(int fromIndex, int toIndex, int newIndex)

Moves the media item range to the new index.

void

Prepares the player.

void

Releases the player.

void

Unregister a listener registered through addListener.

void
removeMediaItems(int fromIndex, int toIndex)

Removes a range of media items from the playlist.

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

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

void
seekTo(
    int mediaItemIndex,
    long positionMs,
    @Player.Command int seekCommand,
    boolean isRepeatingCurrentItem
)

Seeks to a position in the specified MediaItem.

void
setDeviceMuted(boolean muted)

This method is deprecated.

Use setDeviceMuted instead.

void
setDeviceMuted(boolean muted, @C.VolumeFlags int flags)

Sets the mute state of the device.

void
setDeviceVolume(int volume)

This method is deprecated.

Use setDeviceVolume instead.

void
setDeviceVolume(int volume, @C.VolumeFlags int flags)

Sets the volume of the device with volume flags.

void
setMediaItems(List<MediaItem> mediaItems, boolean resetPosition)

Clears the playlist and adds the specified media items.

void
setMediaItems(
    List<MediaItem> mediaItems,
    int startIndex,
    long startPositionMs
)

Clears the playlist and adds the specified media items.

void
setPlayWhenReady(boolean playWhenReady)

Sets whether playback should proceed when getPlaybackState == STATE_READY.

void

Attempts to set the playback parameters.

void

Sets the playlist MediaMetadata.

void

Sets the RepeatMode to be used for playback.

void
setShuffleModeEnabled(boolean shuffleModeEnabled)

Sets whether shuffling of media items is enabled.

void

Sets the parameters constraining the track selection.

void

Sets the Surface onto which video will be rendered.

void

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

void

Sets the SurfaceView onto which video will be rendered.

void

Sets the TextureView onto which video will be rendered.

void
setVolume(float volume)

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

void

Stops playback without resetting the playlist.

Public constructors

StubExoPlayer

public StubExoPlayer()

Public methods

addAnalyticsListener

public void addAnalyticsListener(AnalyticsListener listener)

Adds an AnalyticsListener to receive analytics events.

This method can be called from any thread.

Parameters
AnalyticsListener listener

The listener to be added.

addAudioOffloadListener

public void addAudioOffloadListener(ExoPlayer.AudioOffloadListener listener)

Adds a listener to receive audio offload events.

This method can be called from any thread.

Parameters
ExoPlayer.AudioOffloadListener listener

The listener to register.

addMediaSource

public void addMediaSource(MediaSource mediaSource)

Adds a media source to the end of the playlist.

Parameters
MediaSource mediaSource

The MediaSource to add.

addMediaSource

public void addMediaSource(int index, MediaSource mediaSource)

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

Parameters
int index

The index at which to add the source.

MediaSource mediaSource

The MediaSource to add.

addMediaSources

public void addMediaSources(List<MediaSource> mediaSources)

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

Parameters
List<MediaSource> mediaSources

The MediaSources to add.

addMediaSources

public void addMediaSources(int index, List<MediaSource> mediaSources)

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

Parameters
int index

The index at which to add the media sources.

List<MediaSource> mediaSources

The MediaSources to add.

clearAuxEffectInfo

public void clearAuxEffectInfo()

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

clearCameraMotionListener

public void clearCameraMotionListener(CameraMotionListener listener)

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

Parameters
CameraMotionListener listener

The listener to clear.

clearVideoFrameMetadataListener

public void clearVideoFrameMetadataListener(VideoFrameMetadataListener listener)

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

Parameters
VideoFrameMetadataListener listener

The listener to clear.

createMessage

public PlayerMessage createMessage(PlayerMessage.Target target)

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

public AnalyticsCollector getAnalyticsCollector()

Returns the AnalyticsCollector used for collecting analytics events.

getAudioComponent

public ExoPlayer.AudioComponent getAudioComponent()

getAudioDecoderCounters

public @Nullable DecoderCounters getAudioDecoderCounters()

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

getAudioFormat

public @Nullable Format getAudioFormat()

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

getAudioSessionId

public int getAudioSessionId()

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

getClock

public Clock getClock()

Returns the Clock used for playback.

This method can be called from any thread.

getCurrentTrackGroups

public TrackGroupArray getCurrentTrackGroups()

getCurrentTrackSelections

public TrackSelectionArray getCurrentTrackSelections()

getDeviceComponent

public ExoPlayer.DeviceComponent getDeviceComponent()

getPauseAtEndOfMediaItems

public boolean getPauseAtEndOfMediaItems()

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

getPlaybackLooper

public Looper getPlaybackLooper()

Returns the Looper associated with the playback thread.

This method may be called from any thread.

getPlayerError

public ExoPlaybackException getPlayerError()

Returns the error that caused playback to fail. This is the same error that will have been reported via onPlayerError at the time of failure. It can be queried using this method until the player is re-prepared.

Note that this method will always return null if getPlaybackState is not STATE_IDLE.

Returns
ExoPlaybackException

The error, or null.

See also
onPlayerError

getRenderer

public Renderer getRenderer(int index)

Returns the renderer at the given index.

Parameters
int index

The index of the renderer.

Returns
Renderer

The renderer at this index.

getRendererCount

public int getRendererCount()

Returns the number of renderers.

getRendererType

public int getRendererType(int index)

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
int index

The index of the renderer.

Returns
int

The track type that the renderer handles.

getSeekParameters

public SeekParameters getSeekParameters()

Returns the currently active SeekParameters of the player.

getSkipSilenceEnabled

public boolean getSkipSilenceEnabled()

Returns whether skipping silences in the audio stream is enabled.

getTextComponent

public ExoPlayer.TextComponent getTextComponent()

getTrackSelector

public @Nullable TrackSelector getTrackSelector()

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

getVideoChangeFrameRateStrategy

public int getVideoChangeFrameRateStrategy()

Returns the C.VideoChangeFrameRateStrategy.

getVideoComponent

public ExoPlayer.VideoComponent getVideoComponent()

getVideoDecoderCounters

public @Nullable DecoderCounters getVideoDecoderCounters()

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

getVideoFormat

public @Nullable Format getVideoFormat()

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

getVideoScalingMode

public int getVideoScalingMode()

Returns the C.VideoScalingMode.

isSleepingForOffload

public boolean isSleepingForOffload()

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

public boolean isTunnelingEnabled()

Returns whether tunneling is enabled for the currently selected tracks.

See also
onTracksChanged

prepare

public void prepare(MediaSource mediaSource)

prepare

public void prepare(
    MediaSource mediaSource,
    boolean resetPosition,
    boolean resetState
)

removeAnalyticsListener

public void removeAnalyticsListener(AnalyticsListener listener)

Removes an AnalyticsListener.

Parameters
AnalyticsListener listener

The listener to be removed.

removeAudioOffloadListener

public void removeAudioOffloadListener(ExoPlayer.AudioOffloadListener listener)

Removes a listener of audio offload events.

Parameters
ExoPlayer.AudioOffloadListener listener

The listener to unregister.

setAudioAttributes

public void setAudioAttributes(
    AudioAttributes audioAttributes,
    boolean handleAudioFocus
)

Sets the attributes for audio playback, used by the underlying audio track. If not set, the default audio attributes will be used. They are suitable for general media playback.

Setting the audio attributes during playback may introduce a short gap in audio output as the audio track is recreated. A new audio session id will also be generated.

If tunneling is enabled by the track selector, the specified audio attributes will be ignored, but they will take effect if audio is later played without tunneling.

If the device is running a build before platform API version 21, audio attributes cannot be set directly on the underlying audio track. In this case, the usage will be mapped onto an equivalent stream type using getStreamTypeForAudioUsage.

If audio focus should be handled, the usage must be USAGE_MEDIA or USAGE_GAME. Other usages will throw an .

This method must only be called if COMMAND_SET_AUDIO_ATTRIBUTES is available.

Parameters
AudioAttributes audioAttributes

The attributes to use for audio playback.

boolean handleAudioFocus

True if the player should handle audio focus, false otherwise.

setAudioSessionId

public void setAudioSessionId(int audioSessionId)

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
int audioSessionId

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

setAuxEffectInfo

public void setAuxEffectInfo(AuxEffectInfo auxEffectInfo)

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

setCameraMotionListener

public void setCameraMotionListener(CameraMotionListener listener)

Sets a listener of camera motion events.

Parameters
CameraMotionListener listener

The listener.

setForegroundMode

public void setForegroundMode(boolean foregroundMode)

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
boolean foregroundMode

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

setHandleAudioBecomingNoisy

public void setHandleAudioBecomingNoisy(boolean handleAudioBecomingNoisy)

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
boolean handleAudioBecomingNoisy

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

setImageOutput

public void setImageOutput(ImageOutput imageOutput)

Sets the ImageOutput where rendered images will be forwarded.

Parameters
ImageOutput imageOutput

The ImageOutput.

setMediaSource

public void setMediaSource(MediaSource mediaSource)

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

Parameters
MediaSource mediaSource

The new MediaSource.

setMediaSource

public void setMediaSource(MediaSource mediaSource, boolean resetPosition)

Clears the playlist and adds the specified MediaSource.

Parameters
MediaSource mediaSource

The new MediaSource.

boolean resetPosition

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

public void setMediaSource(MediaSource mediaSource, long startPositionMs)

Clears the playlist and adds the specified MediaSource.

Parameters
MediaSource mediaSource

The new MediaSource.

long startPositionMs

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

setMediaSources

public void setMediaSources(List<MediaSource> mediaSources)

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

Parameters
List<MediaSource> mediaSources

The new MediaSources.

setMediaSources

public void setMediaSources(List<MediaSource> mediaSources, boolean resetPosition)

Clears the playlist and adds the specified MediaSources.

Parameters
List<MediaSource> mediaSources

The new MediaSources.

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

setMediaSources

public void setMediaSources(
    List<MediaSource> mediaSources,
    int startMediaItemIndex,
    long startPositionMs
)

Clears the playlist and adds the specified MediaSources.

Parameters
List<MediaSource> mediaSources

The new MediaSources.

int startMediaItemIndex

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

long startPositionMs

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

public void setPauseAtEndOfMediaItems(boolean pauseAtEndOfMediaItems)

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
boolean pauseAtEndOfMediaItems

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

setPreferredAudioDevice

public void setPreferredAudioDevice(@Nullable AudioDeviceInfo audioDeviceInfo)

Sets the preferred audio device.

Parameters
@Nullable AudioDeviceInfo audioDeviceInfo

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

setPriorityTaskManager

public void setPriorityTaskManager(
    @Nullable PriorityTaskManager priorityTaskManager
)

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
@Nullable PriorityTaskManager priorityTaskManager

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

setSeekParameters

public void setSeekParameters(@Nullable SeekParameters seekParameters)

Sets the parameters that control how seek operations are performed.

Parameters
@Nullable SeekParameters seekParameters

The seek parameters, or null to use the defaults.

setShuffleOrder

public void setShuffleOrder(ShuffleOrder shuffleOrder)

Sets the shuffle order.

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

Parameters
ShuffleOrder shuffleOrder

The shuffle order.

setSkipSilenceEnabled

public void setSkipSilenceEnabled(boolean skipSilenceEnabled)

Sets whether skipping silences in the audio stream is enabled.

Parameters
boolean skipSilenceEnabled

Whether skipping silences in the audio stream is enabled.

setVideoChangeFrameRateStrategy

public void setVideoChangeFrameRateStrategy(int videoChangeFrameRateStrategy)

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
int videoChangeFrameRateStrategy

A C.VideoChangeFrameRateStrategy.

setVideoEffects

public void setVideoEffects(List<Effect> videoEffects)

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
List<Effect> videoEffects

The List of video effects to apply.

setVideoFrameMetadataListener

public void setVideoFrameMetadataListener(VideoFrameMetadataListener listener)

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
VideoFrameMetadataListener listener

The listener.

setVideoScalingMode

public void setVideoScalingMode(int videoScalingMode)

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
int videoScalingMode

The C.VideoScalingMode.

setWakeMode

public void setWakeMode(int wakeMode)

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
int wakeMode

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