public interface Player

Known direct subclasses
BasePlayer

Abstract base Player which implements common implementation independent methods.

ExoPlayer

An extensible media player that plays MediaSources.

ForwardingPlayer

A Player that forwards method calls to another Player.

MediaController

A controller that interacts with a MediaSession, a MediaSessionService hosting a MediaSession, or a MediaLibraryService hosting a .

Known indirect subclasses
CastPlayer

Player implementation that communicates with a Cast receiver app.

ForwardingSimpleBasePlayer

A SimpleBasePlayer that forwards all calls to another Player instance.

MediaBrowser

Browses media content offered by a MediaLibraryService in addition to the functions.

SimpleBasePlayer

A base implementation for Player that reduces the number of methods to implement to a minimum.

SimpleExoPlayer

This class is deprecated.

Use ExoPlayer instead.

StubExoPlayer

An abstract ExoPlayer implementation that throws UnsupportedOperationException from every method.

StubPlayer

An abstract Player implementation that throws UnsupportedOperationException from every method.


A media player interface defining high-level functionality, such as the ability to play, pause, seek and query properties of the currently playing media.

Player features and usage

Some important properties of media players that implement this interface are:

  • All methods must be called from a single application thread unless indicated otherwise. Callbacks in registered listeners are called on the same thread.
  • The available functionality can be limited. Player instances provide a set of available commands to signal feature support and users of the interface must only call methods if the corresponding Command is available.
  • Users can register Player.Listener callbacks that get informed about state changes.
  • Player instances need to update the visible state immediately after each method call, even if the actual changes are handled on background threads or even other devices. This simplifies the usage for callers of methods as no asynchronous handling needs to be considered.
  • Player instances can provide playlist operations, like 'set', 'add', 'remove', 'move' or 'replace' of MediaItem instances. The player can also support repeat modes and shuffling within this playlist. The player provides a representing the structure of the playlist and all its items, which can be obtained by calling getCurrentTimeline
  • Player instances can provide seeking within the currently playing item and to other items, using the various seek... methods.
  • Player instances can provide Tracks defining the currently available and selected tracks, which can be obtained by calling getCurrentTracks. Users can also modify track selection behavior by setting TrackSelectionParameters with setTrackSelectionParameters.
  • Player instances can provide MediaMetadata about the currently playing item, which can be obtained by calling getMediaMetadata.
  • Player instances can provide information about ads in its media structure, for example via isPlayingAd.
  • Player instances can accept different types of video outputs, like SurfaceView or TextureView for video rendering.
  • Player instances can handle playback speed, audio attributes, and audio volume.
  • Player instances can provide information about the playback device, which may be remote, and allow to change the device's volume.

API stability guarantees

The majority of the Player interface and its related classes are part of the stable API that guarantees backwards-compatibility for users of the API. Only more advances use cases may need to rely on UnstableApi classes and methods that are subject to incompatible changes or even removal in a future release. Implementors of the Player interface are not covered by these API stability guarantees.

Player state

Users can listen to state changes by adding a Player.Listener with addListener.

The main elements of the overall player state are:

  • Playlist
  • Playback state
    • STATE_IDLE: This is the initial state, the state when the player is stopped, and when playback failed. The player will hold only limited resources in this state. prepare must be called to transition away from this state.
    • STATE_BUFFERING: The player is not able to immediately play from its current position. This mostly happens because more data needs to be loaded.
    • STATE_READY: The player is able to immediately play from its current position.
    • STATE_ENDED: The player finished playing all media, or there is no media to play.
  • Play/Pause, playback suppression and isPlaying
  • Playback position

Note that there are no callbacks for normal playback progression, only for transitions between media items and other position discontinuities. Code that needs to monitor playback progress (for example, an UI progress bar) should query the current position in appropriate intervals.

Implementing the Player interface

Implementing the Player interface is complex, as the interface includes many convenience methods that need to provide a consistent state and behavior, requires correct handling of listeners and available commands, and expects immediate state changes even if methods are internally handled asynchronously. For this reason, implementations are advised to inherit that handles all of these complexities and provides a simpler integration point for implementors of the interface.

Summary

Nested types

@Documented
@Retention(value = RetentionPolicy.SOURCE)
@Target(value = )
@IntDef(value = )
public annotation Player.Command

Commands that indicate which method calls are currently permitted on a particular Player instance.

public final class Player.Commands

A set of commands.

A builder for Commands instances.

@Documented
@Retention(value = RetentionPolicy.SOURCE)
@Target(value = )
@IntDef(value = )
public annotation Player.DiscontinuityReason

Reasons for position discontinuities.

@Documented
@Retention(value = RetentionPolicy.SOURCE)
@Target(value = )
@IntDef(value = )
public annotation Player.Event

Events that can be reported via onEvents.

public final class Player.Events

A set of events.

public interface Player.Listener

Listener for changes in a Player.

@Documented
@Retention(value = RetentionPolicy.SOURCE)
@Target(value = )
@IntDef(value = )
public annotation Player.MediaItemTransitionReason

Reasons for media item transitions.

@Documented
@Retention(value = RetentionPolicy.SOURCE)
@Target(value = )
@IntDef(value = )
public annotation Player.PlayWhenReadyChangeReason

Reasons for playWhenReady changes.

@Documented
@Retention(value = RetentionPolicy.SOURCE)
@Target(value = )
@IntDef(value = )
public annotation Player.PlaybackSuppressionReason

Reason why playback is suppressed even though getPlayWhenReady is true.

public final class Player.PositionInfo

Position info describing a playback position involved in a discontinuity.

@Documented
@Retention(value = RetentionPolicy.SOURCE)
@Target(value = )
@IntDef(value = )
public annotation Player.RepeatMode

Repeat modes for playback.

@Documented
@Retention(value = RetentionPolicy.SOURCE)
@Target(value = )
@IntDef(value = )
public annotation Player.State

Playback state.

@Documented
@Retention(value = RetentionPolicy.SOURCE)
@Target(value = )
@IntDef(value = )
public annotation Player.TimelineChangeReason

Reasons for timeline changes.

Constants

default static final int

This field is deprecated.

Use COMMAND_ADJUST_DEVICE_VOLUME_WITH_FLAGS instead.

default static final int

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

default static final int

Command to change the media items in the playlist.

default static final int

Command to get the player current AudioAttributes.

default static final int

Command to get information about the currently playing MediaItem.

default static final int

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

default static final int

This field is deprecated.

Use COMMAND_GET_METADATA instead.

default static final int

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

default static final int

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

default static final int

Command to get the information about the current timeline.

default static final int

Command to get details of the current track selection.

default static final int

Command to get the player volume.

default static final int

Represents an invalid Command.

default static final int

Command to start, pause or resume playback.

default static final int

Command to prepare the player.

default static final int

Command to release the player.

default static final int

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

default static final int

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

default static final int

Command to seek anywhere inside the current MediaItem.

default static final int

This field is deprecated.

Use COMMAND_SEEK_IN_CURRENT_MEDIA_ITEM instead.

default static final int

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

default static final int

Command to seek anywhere in any MediaItem.

default static final int

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

default static final int

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

default static final int

This field is deprecated.

Use COMMAND_SEEK_TO_NEXT_MEDIA_ITEM instead.

default static final int

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

default static final int

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

default static final int

This field is deprecated.

Use COMMAND_SEEK_TO_PREVIOUS_MEDIA_ITEM instead.

default static final int

This field is deprecated.

Use COMMAND_SEEK_TO_MEDIA_ITEM instead.

default static final int

Command to set the player's audio attributes.

default static final int

This field is deprecated.

Use COMMAND_SET_DEVICE_VOLUME_WITH_FLAGS instead.

default static final int

Command to set the device volume with volume flags.

default static final int

Command to set a MediaItem.

default static final int

This field is deprecated.

Use COMMAND_SET_PLAYLIST_METADATA instead.

default static final int

Command to set the playlist metadata.

default static final int

Command to set the repeat mode.

default static final int

Command to enable shuffling.

default static final int

Command to set the playback speed and pitch.

default static final int

Command to set the player's track selection parameters.

default static final int

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

default static final int

Command to set the player volume.

default static final int

Command to stop playback.

default static final int

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

default static final int

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

default static final int

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

default static final int

Seek within the current period or to another period.

default static final int

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

default static final int

Discontinuity introduced by a skipped silence.

default static final int

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

default static final int

getAudioAttributes changed.

default static final int

The audio session id was set.

default static final int

isCommandAvailable changed for at least one Command.

default static final int

getCurrentCues changed.

default static final int

getDeviceInfo changed.

default static final int

getDeviceVolume changed.

default static final int

isLoading ()} changed.

default static final int

isPlaying changed.

default static final int

getMaxSeekToPreviousPosition changed.

default static final int

getCurrentMediaItem changed or the player started repeating the current item.

default static final int

getMediaMetadata changed.

default static final int

Metadata associated with the current playback time changed.

default static final int

getPlaybackParameters changed.

default static final int

getPlaybackState changed.

default static final int

getPlaybackSuppressionReason changed.

default static final int

getPlayerError changed.

default static final int

getPlaylistMetadata changed.

default static final int

getPlayWhenReady changed.

default static final int

A position discontinuity occurred.

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

default static final int

getRepeatMode changed.

default static final int

getSeekBackIncrement changed.

default static final int

getSeekForwardIncrement changed.

default static final int

getShuffleModeEnabled changed.

default static final int

Skipping silences in the audio stream is enabled or disabled.

default static final int

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

default static final int

getCurrentTimeline changed.

default static final int

getCurrentTracks changed.

default static final int

getTrackSelectionParameters changed.

default static final int

getVideoSize changed.

default static final int

getVolume changed.

default static final int

Playback has automatically transitioned to the next media item.

default static final int

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

default static final int

The media item has been repeated.

default static final int

A seek to another media item has occurred.

default static final int

Playback is not suppressed.

default static final int

Playback is suppressed due to transient audio focus loss.

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

default static final int

This field is deprecated.

Use PLAYBACK_SUPPRESSION_REASON_UNSUITABLE_AUDIO_OUTPUT instead.

default static final int

Playback has been paused to avoid becoming noisy.

default static final int

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

default static final int

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

default static final int

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

default static final int

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

default static final int

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

default static final int

Repeats the entire timeline infinitely.

default static final int

Normal playback without repetition.

default static final int

Repeats the currently playing MediaItem infinitely during ongoing playback.

default static final int

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

default static final int

The player has finished playing the media.

default static final int

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

default static final int

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

default static final int

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

default static final int

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

Public methods

abstract void

Registers a listener to receive all events from the player.

abstract void

Adds a media item to the end of the playlist.

abstract void
addMediaItem(int index, MediaItem mediaItem)

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

abstract void

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

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

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

abstract boolean

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

abstract void

Clears the playlist.

abstract void

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

abstract void

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

abstract void

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

abstract void

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

abstract void

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

abstract void

This method is deprecated.

Use decreaseDeviceVolume instead.

abstract void

Decreases the volume of the device.

abstract Looper

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

abstract AudioAttributes

Returns the attributes for audio playback.

abstract Player.Commands

Returns the player's currently available Commands.

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

abstract long

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

abstract long

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

abstract long

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

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

abstract int

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

abstract int

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

abstract CueGroup

Returns the current CueGroup.

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

abstract @Nullable Object

Returns the current manifest.

abstract @Nullable MediaItem

Returns the currently playing MediaItem.

abstract int

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

abstract int

Returns the index of the period currently being played.

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

abstract Timeline

Returns the current Timeline.

abstract Tracks

Returns the current tracks.

abstract int

This method is deprecated.

Use getCurrentMediaItemIndex instead.

abstract DeviceInfo

Gets the device information.

abstract @IntRange(from = 0) int

Gets the current volume of the device.

abstract long

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

abstract long

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

abstract MediaItem
getMediaItemAt(int index)

Returns the MediaItem at the given index.

abstract int

Returns the number of media items in the playlist.

abstract MediaMetadata

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

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

abstract int

This method is deprecated.

Use getNextMediaItemIndex instead.

abstract boolean

Whether playback will proceed when getPlaybackState == STATE_READY.

abstract PlaybackParameters

Returns the currently active playback parameters.

abstract int

Returns the current playback state of the player.

abstract int

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

abstract @Nullable PlaybackException

Returns the error that caused playback to fail.

abstract MediaMetadata

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

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

abstract int

This method is deprecated.

Use getPreviousMediaItemIndex instead.

abstract int

Returns the current RepeatMode used for playback.

abstract long

Returns the seekBack increment.

abstract long

Returns the seekForward increment.

abstract boolean

Returns whether shuffling of media items is enabled.

abstract Size

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

abstract long

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

abstract TrackSelectionParameters

Returns the parameters constraining the track selection.

abstract VideoSize

Gets the size of the video.

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

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

abstract boolean

This method is deprecated.

Use hasNextMediaItem instead.

abstract boolean

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

abstract boolean

This method is deprecated.

Use hasNextMediaItem instead.

abstract boolean

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

abstract void

This method is deprecated.

Use increaseDeviceVolume instead.

abstract void

Increases the volume of the device.

abstract boolean

Returns whether the provided Command is available.

abstract boolean

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

abstract boolean

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

abstract boolean

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

abstract boolean

This method is deprecated.

Use isCurrentMediaItemDynamic instead.

abstract boolean

This method is deprecated.

Use isCurrentMediaItemLive instead.

abstract boolean

This method is deprecated.

Use isCurrentMediaItemSeekable instead.

abstract boolean

Gets whether the device is muted or not.

abstract boolean

Whether the player is currently loading the source.

abstract boolean

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

abstract boolean

Returns whether the player is currently playing an ad.

abstract void
moveMediaItem(int currentIndex, int newIndex)

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

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

Moves the media item range to the new index.

abstract void

This method is deprecated.

Use seekToNextMediaItem instead.

abstract void

Pauses playback.

abstract void

Resumes playback as soon as getPlaybackState == STATE_READY.

abstract void

Prepares the player.

abstract void

Releases the player.

abstract void

Unregister a listener registered through addListener.

abstract void
removeMediaItem(int index)

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

abstract void
removeMediaItems(int fromIndex, int toIndex)

Removes a range of media items from the playlist.

abstract void
replaceMediaItem(int index, MediaItem mediaItem)

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

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

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

abstract void

Seeks back in the current MediaItem by getSeekBackIncrement milliseconds.

abstract void

Seeks forward in the current MediaItem by getSeekForwardIncrement milliseconds.

abstract void
seekTo(long positionMs)

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

abstract void
seekTo(int mediaItemIndex, long positionMs)

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

abstract void

Seeks to the default position associated with the current MediaItem.

abstract void
seekToDefaultPosition(int mediaItemIndex)

Seeks to the default position associated with the specified MediaItem.

abstract void

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

abstract void

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

abstract void

This method is deprecated.

Use seekToNextMediaItem instead.

abstract void

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

abstract void

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

abstract void

This method is deprecated.

Use seekToPreviousMediaItem instead.

abstract void
setAudioAttributes(
    AudioAttributes audioAttributes,
    boolean handleAudioFocus
)

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

abstract void
setDeviceMuted(boolean muted)

This method is deprecated.

Use setDeviceMuted instead.

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

Sets the mute state of the device.

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

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

abstract void
setMediaItem(MediaItem mediaItem, boolean resetPosition)

Clears the playlist and adds the specified MediaItem.

abstract void
setMediaItem(MediaItem mediaItem, long startPositionMs)

Clears the playlist and adds the specified MediaItem.

abstract void

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

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

Clears the playlist and adds the specified media items.

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

Clears the playlist and adds the specified media items.

abstract void
setPlayWhenReady(boolean playWhenReady)

Sets whether playback should proceed when getPlaybackState == STATE_READY.

abstract void

Attempts to set the playback parameters.

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

Changes the rate at which playback occurs.

abstract void

Sets the playlist MediaMetadata.

abstract void

Sets the RepeatMode to be used for playback.

abstract void
setShuffleModeEnabled(boolean shuffleModeEnabled)

Sets whether shuffling of media items is enabled.

abstract void

Sets the parameters constraining the track selection.

abstract void

Sets the Surface onto which video will be rendered.

abstract void

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

abstract void

Sets the SurfaceView onto which video will be rendered.

abstract void

Sets the TextureView onto which video will be rendered.

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.

abstract void

Stops playback without resetting the playlist.

Extension functions

default final @NonNull Void

Continuously listens to the Player.Listener.onEvents callback, passing the received Player.Events to the provided onEvents function.

Constants

COMMAND_ADJUST_DEVICE_VOLUME

default static final int COMMAND_ADJUST_DEVICE_VOLUME = 26

COMMAND_ADJUST_DEVICE_VOLUME_WITH_FLAGS

default static final int COMMAND_ADJUST_DEVICE_VOLUME_WITH_FLAGS = 34

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

The following methods must only be called if this command is available:

COMMAND_CHANGE_MEDIA_ITEMS

default static final int COMMAND_CHANGE_MEDIA_ITEMS = 20

Command to change the media items in the playlist.

The following methods must only be called if this command is available:

COMMAND_GET_AUDIO_ATTRIBUTES

default static final int COMMAND_GET_AUDIO_ATTRIBUTES = 21

Command to get the player current AudioAttributes.

The getAudioAttributes method must only be called if this command is available.

COMMAND_GET_DEVICE_VOLUME

default static final int COMMAND_GET_DEVICE_VOLUME = 23

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

The following methods must only be called if this command is available:

COMMAND_GET_MEDIA_ITEMS_METADATA

default static final int COMMAND_GET_MEDIA_ITEMS_METADATA = 18

COMMAND_GET_METADATA

default static final int COMMAND_GET_METADATA = 18

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

The following methods must only be called if this command is available:

COMMAND_GET_TEXT

default static final int COMMAND_GET_TEXT = 28

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

The getCurrentCues method must only be called if this command is available.

COMMAND_GET_TIMELINE

default static final int COMMAND_GET_TIMELINE = 17

Command to get the information about the current timeline.

The following methods must only be called if this command is available:

COMMAND_GET_TRACKS

default static final int COMMAND_GET_TRACKS = 30

Command to get details of the current track selection.

The getCurrentTracks method must only be called if this command is available.

COMMAND_GET_VOLUME

default static final int COMMAND_GET_VOLUME = 22

Command to get the player volume.

The getVolume method must only be called if this command is available.

COMMAND_INVALID

default static final int COMMAND_INVALID = -1

Represents an invalid Command.

COMMAND_PLAY_PAUSE

default static final int COMMAND_PLAY_PAUSE = 1

Command to start, pause or resume playback.

The following methods must only be called if this command is available:

COMMAND_PREPARE

default static final int COMMAND_PREPARE = 2

Command to prepare the player.

The prepare method must only be called if this command is available.

COMMAND_RELEASE

default static final int COMMAND_RELEASE = 32

Command to release the player.

The release method must only be called if this command is available.

COMMAND_SEEK_BACK

default static final int COMMAND_SEEK_BACK = 11

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

The seekBack method must only be called if this command is available.

COMMAND_SEEK_FORWARD

default static final int COMMAND_SEEK_FORWARD = 12

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

The seekForward method must only be called if this command is available.

COMMAND_SEEK_IN_CURRENT_MEDIA_ITEM

default static final int COMMAND_SEEK_IN_CURRENT_MEDIA_ITEM = 5

Command to seek anywhere inside the current MediaItem.

The seekTo method must only be called if this command is available.

COMMAND_SEEK_IN_CURRENT_WINDOW

@UnstableApi
default static final int COMMAND_SEEK_IN_CURRENT_WINDOW = 5

COMMAND_SEEK_TO_DEFAULT_POSITION

default static final int COMMAND_SEEK_TO_DEFAULT_POSITION = 4

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

The seekToDefaultPosition method must only be called if this command is available.

COMMAND_SEEK_TO_MEDIA_ITEM

default static final int COMMAND_SEEK_TO_MEDIA_ITEM = 10

Command to seek anywhere in any MediaItem.

The following methods must only be called if this command is available:

COMMAND_SEEK_TO_NEXT

default static final int COMMAND_SEEK_TO_NEXT = 9

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

The seekToNext method must only be called if this command is available.

COMMAND_SEEK_TO_NEXT_MEDIA_ITEM

default static final int COMMAND_SEEK_TO_NEXT_MEDIA_ITEM = 8

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

The seekToNextMediaItem method must only be called if this command is available.

COMMAND_SEEK_TO_NEXT_WINDOW

@UnstableApi
default static final int COMMAND_SEEK_TO_NEXT_WINDOW = 8

COMMAND_SEEK_TO_PREVIOUS

default static final int COMMAND_SEEK_TO_PREVIOUS = 7

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

The seekToPrevious method must only be called if this command is available.

COMMAND_SEEK_TO_PREVIOUS_MEDIA_ITEM

default static final int COMMAND_SEEK_TO_PREVIOUS_MEDIA_ITEM = 6

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

The seekToPreviousMediaItem method must only be called if this command is available.

COMMAND_SEEK_TO_PREVIOUS_WINDOW

@UnstableApi
default static final int COMMAND_SEEK_TO_PREVIOUS_WINDOW = 6

COMMAND_SEEK_TO_WINDOW

@UnstableApi
default static final int COMMAND_SEEK_TO_WINDOW = 10

COMMAND_SET_AUDIO_ATTRIBUTES

default static final int COMMAND_SET_AUDIO_ATTRIBUTES = 35

Command to set the player's audio attributes.

The setAudioAttributes method must only be called if this command is available.

COMMAND_SET_DEVICE_VOLUME

default static final int COMMAND_SET_DEVICE_VOLUME = 25

COMMAND_SET_DEVICE_VOLUME_WITH_FLAGS

default static final int COMMAND_SET_DEVICE_VOLUME_WITH_FLAGS = 33

Command to set the device volume with volume flags.

The setDeviceVolume method must only be called if this command is available.

COMMAND_SET_MEDIA_ITEM

default static final int COMMAND_SET_MEDIA_ITEM = 31

Command to set a MediaItem.

The following methods must only be called if this command is available:

COMMAND_SET_MEDIA_ITEMS_METADATA

default static final int COMMAND_SET_MEDIA_ITEMS_METADATA = 19

COMMAND_SET_PLAYLIST_METADATA

default static final int COMMAND_SET_PLAYLIST_METADATA = 19

Command to set the playlist metadata.

The setPlaylistMetadata method must only be called if this command is available.

COMMAND_SET_REPEAT_MODE

default static final int COMMAND_SET_REPEAT_MODE = 15

Command to set the repeat mode.

The setRepeatMode method must only be called if this command is available.

COMMAND_SET_SHUFFLE_MODE

default static final int COMMAND_SET_SHUFFLE_MODE = 14

Command to enable shuffling.

The setShuffleModeEnabled method must only be called if this command is available.

COMMAND_SET_SPEED_AND_PITCH

default static final int COMMAND_SET_SPEED_AND_PITCH = 13

Command to set the playback speed and pitch.

The following methods must only be called if this command is available:

COMMAND_SET_TRACK_SELECTION_PARAMETERS

default static final int COMMAND_SET_TRACK_SELECTION_PARAMETERS = 29

Command to set the player's track selection parameters.

The setTrackSelectionParameters method must only be called if this command is available.

COMMAND_SET_VIDEO_SURFACE

default static final int COMMAND_SET_VIDEO_SURFACE = 27

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

The following methods must only be called if this command is available:

COMMAND_SET_VOLUME

default static final int COMMAND_SET_VOLUME = 24

Command to set the player volume.

The setVolume method must only be called if this command is available.

COMMAND_STOP

default static final int COMMAND_STOP = 3

Command to stop playback.

The stop method must only be called if this command is available.

DISCONTINUITY_REASON_AUTO_TRANSITION

default static final int DISCONTINUITY_REASON_AUTO_TRANSITION = 0

Automatic playback transition from one period in the timeline to the next. The period index may be the same as it was before the discontinuity in case the current period is repeated.

This reason also indicates an automatic transition from the content period to an inserted ad period or vice versa. Or a transition caused by another player (e.g. multiple controllers can control the same playback on a remote device).

DISCONTINUITY_REASON_INTERNAL

default static final int DISCONTINUITY_REASON_INTERNAL = 5

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

DISCONTINUITY_REASON_REMOVE

default static final int DISCONTINUITY_REASON_REMOVE = 4

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

DISCONTINUITY_REASON_SEEK

default static final int DISCONTINUITY_REASON_SEEK = 1

Seek within the current period or to another period.

DISCONTINUITY_REASON_SEEK_ADJUSTMENT

default static final int DISCONTINUITY_REASON_SEEK_ADJUSTMENT = 2

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

DISCONTINUITY_REASON_SILENCE_SKIP

default static final int DISCONTINUITY_REASON_SILENCE_SKIP = 6

Discontinuity introduced by a skipped silence.

DISCONTINUITY_REASON_SKIP

default static final int DISCONTINUITY_REASON_SKIP = 3

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

EVENT_AUDIO_ATTRIBUTES_CHANGED

default static final int EVENT_AUDIO_ATTRIBUTES_CHANGED = 20

getAudioAttributes changed.

EVENT_AUDIO_SESSION_ID

default static final int EVENT_AUDIO_SESSION_ID = 21

The audio session id was set.

EVENT_AVAILABLE_COMMANDS_CHANGED

default static final int EVENT_AVAILABLE_COMMANDS_CHANGED = 13

isCommandAvailable changed for at least one Command.

EVENT_CUES

default static final int EVENT_CUES = 27

getCurrentCues changed.

EVENT_DEVICE_INFO_CHANGED

default static final int EVENT_DEVICE_INFO_CHANGED = 29

getDeviceInfo changed.

EVENT_DEVICE_VOLUME_CHANGED

default static final int EVENT_DEVICE_VOLUME_CHANGED = 30

getDeviceVolume changed.

EVENT_IS_LOADING_CHANGED

default static final int EVENT_IS_LOADING_CHANGED = 3

isLoading ()} changed.

EVENT_IS_PLAYING_CHANGED

default static final int EVENT_IS_PLAYING_CHANGED = 7

isPlaying changed.

EVENT_MAX_SEEK_TO_PREVIOUS_POSITION_CHANGED

default static final int EVENT_MAX_SEEK_TO_PREVIOUS_POSITION_CHANGED = 18

getMaxSeekToPreviousPosition changed.

EVENT_MEDIA_ITEM_TRANSITION

default static final int EVENT_MEDIA_ITEM_TRANSITION = 1

getCurrentMediaItem changed or the player started repeating the current item.

EVENT_MEDIA_METADATA_CHANGED

default static final int EVENT_MEDIA_METADATA_CHANGED = 14

getMediaMetadata changed.

EVENT_METADATA

default static final int EVENT_METADATA = 28

Metadata associated with the current playback time changed.

EVENT_PLAYBACK_PARAMETERS_CHANGED

default static final int EVENT_PLAYBACK_PARAMETERS_CHANGED = 12

getPlaybackParameters changed.

EVENT_PLAYBACK_STATE_CHANGED

default static final int EVENT_PLAYBACK_STATE_CHANGED = 4

getPlaybackState changed.

EVENT_PLAYBACK_SUPPRESSION_REASON_CHANGED

default static final int EVENT_PLAYBACK_SUPPRESSION_REASON_CHANGED = 6

getPlaybackSuppressionReason changed.

EVENT_PLAYER_ERROR

default static final int EVENT_PLAYER_ERROR = 10

getPlayerError changed.

EVENT_PLAYLIST_METADATA_CHANGED

default static final int EVENT_PLAYLIST_METADATA_CHANGED = 15

getPlaylistMetadata changed.

EVENT_PLAY_WHEN_READY_CHANGED

default static final int EVENT_PLAY_WHEN_READY_CHANGED = 5

getPlayWhenReady changed.

EVENT_POSITION_DISCONTINUITY

default static final int EVENT_POSITION_DISCONTINUITY = 11

A position discontinuity occurred. See onPositionDiscontinuity.

EVENT_RENDERED_FIRST_FRAME

default static final int EVENT_RENDERED_FIRST_FRAME = 26

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.

EVENT_REPEAT_MODE_CHANGED

default static final int EVENT_REPEAT_MODE_CHANGED = 8

getRepeatMode changed.

EVENT_SEEK_BACK_INCREMENT_CHANGED

default static final int EVENT_SEEK_BACK_INCREMENT_CHANGED = 16

getSeekBackIncrement changed.

EVENT_SEEK_FORWARD_INCREMENT_CHANGED

default static final int EVENT_SEEK_FORWARD_INCREMENT_CHANGED = 17

getSeekForwardIncrement changed.

EVENT_SHUFFLE_MODE_ENABLED_CHANGED

default static final int EVENT_SHUFFLE_MODE_ENABLED_CHANGED = 9

getShuffleModeEnabled changed.

EVENT_SKIP_SILENCE_ENABLED_CHANGED

default static final int EVENT_SKIP_SILENCE_ENABLED_CHANGED = 23

Skipping silences in the audio stream is enabled or disabled.

EVENT_SURFACE_SIZE_CHANGED

default static final int EVENT_SURFACE_SIZE_CHANGED = 24

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

EVENT_TIMELINE_CHANGED

default static final int EVENT_TIMELINE_CHANGED = 0

getCurrentTimeline changed.

EVENT_TRACKS_CHANGED

default static final int EVENT_TRACKS_CHANGED = 2

getCurrentTracks changed.

EVENT_TRACK_SELECTION_PARAMETERS_CHANGED

default static final int EVENT_TRACK_SELECTION_PARAMETERS_CHANGED = 19

getTrackSelectionParameters changed.

EVENT_VIDEO_SIZE_CHANGED

default static final int EVENT_VIDEO_SIZE_CHANGED = 25

getVideoSize changed.

EVENT_VOLUME_CHANGED

default static final int EVENT_VOLUME_CHANGED = 22

getVolume changed.

MEDIA_ITEM_TRANSITION_REASON_AUTO

default static final int MEDIA_ITEM_TRANSITION_REASON_AUTO = 1

Playback has automatically transitioned to the next media item.

This reason also indicates a transition caused by another player (e.g. multiple controllers can control the same playback on a remote device).

MEDIA_ITEM_TRANSITION_REASON_PLAYLIST_CHANGED

default static final int MEDIA_ITEM_TRANSITION_REASON_PLAYLIST_CHANGED = 3

The current media item has changed because of a change in the playlist. This can either be if the media item previously being played has been removed, or when the playlist becomes non-empty after being empty.

MEDIA_ITEM_TRANSITION_REASON_REPEAT

default static final int MEDIA_ITEM_TRANSITION_REASON_REPEAT = 0

The media item has been repeated.

MEDIA_ITEM_TRANSITION_REASON_SEEK

default static final int MEDIA_ITEM_TRANSITION_REASON_SEEK = 2

A seek to another media item has occurred.

PLAYBACK_SUPPRESSION_REASON_NONE

default static final int PLAYBACK_SUPPRESSION_REASON_NONE = 0

Playback is not suppressed.

PLAYBACK_SUPPRESSION_REASON_TRANSIENT_AUDIO_FOCUS_LOSS

default static final int PLAYBACK_SUPPRESSION_REASON_TRANSIENT_AUDIO_FOCUS_LOSS = 1

Playback is suppressed due to transient audio focus loss.

PLAYBACK_SUPPRESSION_REASON_UNSUITABLE_AUDIO_OUTPUT

default static final int PLAYBACK_SUPPRESSION_REASON_UNSUITABLE_AUDIO_OUTPUT = 3

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

PLAYBACK_SUPPRESSION_REASON_UNSUITABLE_AUDIO_ROUTE

default static final int PLAYBACK_SUPPRESSION_REASON_UNSUITABLE_AUDIO_ROUTE = 2

PLAY_WHEN_READY_CHANGE_REASON_AUDIO_BECOMING_NOISY

default static final int PLAY_WHEN_READY_CHANGE_REASON_AUDIO_BECOMING_NOISY = 3

Playback has been paused to avoid becoming noisy.

PLAY_WHEN_READY_CHANGE_REASON_AUDIO_FOCUS_LOSS

default static final int PLAY_WHEN_READY_CHANGE_REASON_AUDIO_FOCUS_LOSS = 2

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

PLAY_WHEN_READY_CHANGE_REASON_END_OF_MEDIA_ITEM

default static final int PLAY_WHEN_READY_CHANGE_REASON_END_OF_MEDIA_ITEM = 5

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

PLAY_WHEN_READY_CHANGE_REASON_REMOTE

default static final int PLAY_WHEN_READY_CHANGE_REASON_REMOTE = 4

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

PLAY_WHEN_READY_CHANGE_REASON_SUPPRESSED_TOO_LONG

default static final int PLAY_WHEN_READY_CHANGE_REASON_SUPPRESSED_TOO_LONG = 6

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

PLAY_WHEN_READY_CHANGE_REASON_USER_REQUEST

default static final int PLAY_WHEN_READY_CHANGE_REASON_USER_REQUEST = 1

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

REPEAT_MODE_ALL

default static final int REPEAT_MODE_ALL = 2

Repeats the entire timeline infinitely. "Previous" and "Next" actions behave as they do in REPEAT_MODE_OFF, but with looping at the ends so that "Previous" when playing the first MediaItem will move to the last MediaItem, and "Next" when playing the last MediaItem will move to the first MediaItem.

REPEAT_MODE_OFF

default static final int REPEAT_MODE_OFF = 0

Normal playback without repetition. "Previous" and "Next" actions move to the previous and next MediaItem respectively, and do nothing when there is no previous or next to move to.

REPEAT_MODE_ONE

default static final int REPEAT_MODE_ONE = 1

Repeats the currently playing MediaItem infinitely during ongoing playback. "Previous" and "Next" actions behave as they do in REPEAT_MODE_OFF, moving to the previous and next MediaItem respectively, and doing nothing when there is no previous or next to move to.

STATE_BUFFERING

default static final int STATE_BUFFERING = 2

The player is not able to immediately play the media, but is doing work toward being able to do so. This state typically occurs when the player needs to buffer more data before playback can start.

STATE_ENDED

default static final int STATE_ENDED = 4

The player has finished playing the media.

STATE_IDLE

default static final int STATE_IDLE = 1

The player is idle, meaning it holds only limited resources. The player must be prepared before it will play the media.

STATE_READY

default static final int STATE_READY = 3

The player is able to immediately play from its current position. The player will be playing if getPlayWhenReady is true, and paused otherwise.

TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED

default static final int TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED = 0

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

TIMELINE_CHANGE_REASON_SOURCE_UPDATE

default static final int TIMELINE_CHANGE_REASON_SOURCE_UPDATE = 1

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

This reason also indicates a change caused by another player (e.g. multiple controllers can control the same playback on the remote device).

Public methods

addListener

abstract void addListener(Player.Listener listener)

Registers a listener to receive all events from the player.

The listener's methods will be called on the thread associated with getApplicationLooper.

This method can be called from any thread.

Parameters
Player.Listener listener

The listener to register.

addMediaItem

abstract void addMediaItem(MediaItem mediaItem)

Adds a media item to the end of the playlist.

This method must only be called if COMMAND_CHANGE_MEDIA_ITEMS is available.

Parameters
MediaItem mediaItem

The MediaItem to add.

addMediaItem

abstract void addMediaItem(int index, MediaItem mediaItem)

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

This method must only be called if COMMAND_CHANGE_MEDIA_ITEMS is available.

Parameters
int index

The index at which to add the media item. If the index is larger than the size of the playlist, the media item is added to the end of the playlist.

MediaItem mediaItem

The MediaItem to add.

addMediaItems

abstract void addMediaItems(List<MediaItem> mediaItems)

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

This method must only be called if COMMAND_CHANGE_MEDIA_ITEMS is available.

Parameters
List<MediaItem> mediaItems

The media items to add.

addMediaItems

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

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

This method must only be called if COMMAND_CHANGE_MEDIA_ITEMS is available.

Parameters
int index

The index at which to add the media items. If the index is larger than the size of the playlist, the media items are added to the end of the playlist.

List<MediaItem> mediaItems

The media items to add.

canAdvertiseSession

abstract boolean canAdvertiseSession()

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

clearMediaItems

abstract void clearMediaItems()

Clears the playlist.

This method must only be called if COMMAND_CHANGE_MEDIA_ITEMS is available.

clearVideoSurface

abstract void clearVideoSurface()

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

This method must only be called if COMMAND_SET_VIDEO_SURFACE is available.

clearVideoSurface

abstract void clearVideoSurface(@Nullable Surface surface)

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

This method must only be called if COMMAND_SET_VIDEO_SURFACE is available.

Parameters
@Nullable Surface surface

The surface to clear.

clearVideoSurfaceHolder

abstract void clearVideoSurfaceHolder(@Nullable SurfaceHolder surfaceHolder)

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

This method must only be called if COMMAND_SET_VIDEO_SURFACE is available.

Parameters
@Nullable SurfaceHolder surfaceHolder

The surface holder to clear.

clearVideoSurfaceView

abstract void clearVideoSurfaceView(@Nullable SurfaceView surfaceView)

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

This method must only be called if COMMAND_SET_VIDEO_SURFACE is available.

Parameters
@Nullable SurfaceView surfaceView

The texture view to clear.

clearVideoTextureView

abstract void clearVideoTextureView(@Nullable TextureView textureView)

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

This method must only be called if COMMAND_SET_VIDEO_SURFACE is available.

Parameters
@Nullable TextureView textureView

The texture view to clear.

decreaseDeviceVolume

abstract void decreaseDeviceVolume()

decreaseDeviceVolume

abstract void decreaseDeviceVolume(@C.VolumeFlags int flags)

Decreases the volume of the device.

The getDeviceVolume device volume cannot be decreased below minVolume.

Note that this method affects the device volume. To change the volume of the current stream only, use setVolume.

This method must only be called if COMMAND_ADJUST_DEVICE_VOLUME_WITH_FLAGS is available.

Parameters
@C.VolumeFlags int flags

Either 0 or a bitwise combination of one or more C.VolumeFlags.

getApplicationLooper

abstract Looper getApplicationLooper()

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

This method can be called from any thread.

getAudioAttributes

abstract AudioAttributes getAudioAttributes()

Returns the attributes for audio playback.

This method must only be called if COMMAND_GET_AUDIO_ATTRIBUTES is available.

getAvailableCommands

abstract Player.Commands getAvailableCommands()

Returns the player's currently available Commands.

The returned Commands are not updated when available commands change. Use onAvailableCommandsChanged to get an update when the available commands change.

Returns
Player.Commands

The currently available Commands.

getBufferedPercentage

abstract @IntRange(from = 0, to = 100) int getBufferedPercentage()

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.

getBufferedPosition

abstract long getBufferedPosition()

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

This method must only be called if COMMAND_GET_CURRENT_MEDIA_ITEM is available.

getContentBufferedPosition

abstract long getContentBufferedPosition()

If isPlayingAd returns true, returns an estimate of the content position in the current content up to which data is buffered, in milliseconds. If there is no ad playing, the returned position is the same as that returned by getBufferedPosition.

This method must only be called if COMMAND_GET_CURRENT_MEDIA_ITEM is available.

getContentDuration

abstract long getContentDuration()

If isPlayingAd returns true, returns the duration of the current content in milliseconds, or TIME_UNSET if the duration is not known. If there is no ad playing, the returned duration is the same as that returned by getDuration.

This method must only be called if COMMAND_GET_CURRENT_MEDIA_ITEM is available.

getContentPosition

abstract long getContentPosition()

If isPlayingAd returns true, returns the content position that will be played once all ads in the ad group have finished playing, in milliseconds. If there is no ad playing, the returned position is the same as that returned by getCurrentPosition.

This method must only be called if COMMAND_GET_CURRENT_MEDIA_ITEM is available.

getCurrentAdGroupIndex

abstract int getCurrentAdGroupIndex()

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

This method must only be called if COMMAND_GET_CURRENT_MEDIA_ITEM is available.

getCurrentAdIndexInAdGroup

abstract int getCurrentAdIndexInAdGroup()

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

This method must only be called if COMMAND_GET_CURRENT_MEDIA_ITEM is available.

getCurrentCues

abstract CueGroup getCurrentCues()

Returns the current CueGroup.

This method must only be called if COMMAND_GET_TEXT is available.

See also
onCues

getCurrentLiveOffset

abstract long getCurrentLiveOffset()

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.

The offset is calculated as currentTime - playbackPosition, so should usually be positive.

Note that this offset may rely on an accurate local time, so this method may return an incorrect value if the difference between system clock and server clock is unknown.

This method must only be called if COMMAND_GET_CURRENT_MEDIA_ITEM is available.

getCurrentManifest

@UnstableApi
abstract @Nullable Object getCurrentManifest()

Returns the current manifest. The type depends on the type of media being played. May be null.

getCurrentMediaItem

abstract @Nullable MediaItem getCurrentMediaItem()

Returns the currently playing MediaItem. May be null if the timeline is empty.

This method must only be called if COMMAND_GET_CURRENT_MEDIA_ITEM is available.

getCurrentMediaItemIndex

abstract int getCurrentMediaItemIndex()

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

This method must only be called if COMMAND_GET_TIMELINE is available.

getCurrentPeriodIndex

abstract int getCurrentPeriodIndex()

Returns the index of the period currently being played.

This method must only be called if COMMAND_GET_TIMELINE is available.

getCurrentPosition

abstract long getCurrentPosition()

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

This method must only be called if COMMAND_GET_CURRENT_MEDIA_ITEM is available.

getCurrentTimeline

abstract Timeline getCurrentTimeline()

Returns the current Timeline. Never null, but may be empty.

This method must only be called if COMMAND_GET_TIMELINE is available.

getCurrentTracks

abstract Tracks getCurrentTracks()

Returns the current tracks.

This method must only be called if COMMAND_GET_TRACKS is available.

See also
onTracksChanged

getCurrentWindowIndex

@UnstableApi
abstract int getCurrentWindowIndex()

getDeviceInfo

abstract DeviceInfo getDeviceInfo()

Gets the device information.

getDeviceVolume

abstract @IntRange(from = 0) int getDeviceVolume()

Gets the current volume of the device.

For devices with local playback, the volume returned by this method varies according to the current stream type. The stream type is determined by usage which can be converted to stream type with getStreamTypeForAudioUsage.

For devices with remote playback, the volume of the remote device is returned.

Note that this method returns the volume of the device. To check the current stream volume, use getVolume.

This method must only be called if COMMAND_GET_DEVICE_VOLUME is available.

getDuration

abstract long getDuration()

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

This method must only be called if COMMAND_GET_CURRENT_MEDIA_ITEM is available.

getMaxSeekToPreviousPosition

abstract long getMaxSeekToPreviousPosition()

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

Returns
long

The maximum seek to previous position, in milliseconds.

getMediaItemAt

abstract MediaItem getMediaItemAt(int index)

Returns the MediaItem at the given index.

This method must only be called if COMMAND_GET_TIMELINE is available.

getMediaItemCount

abstract int getMediaItemCount()

Returns the number of media items in the playlist.

This method must only be called if COMMAND_GET_TIMELINE is available.

getMediaMetadata

abstract MediaMetadata getMediaMetadata()

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

This MediaMetadata is a combination of the MediaItem metadata, the static metadata in the media's Format, and any timed metadata that has been parsed from the media and output via onMetadata. If a field is populated in the mediaMetadata, it will be prioritised above the same field coming from static or timed metadata.

This method must only be called if COMMAND_GET_METADATA is available.

getNextMediaItemIndex

abstract int getNextMediaItemIndex()

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. Returns INDEX_UNSET if hasNextMediaItem is false.

Note: When the repeat mode is REPEAT_MODE_ONE, this method behaves the same as when the current repeat mode is REPEAT_MODE_OFF. See REPEAT_MODE_ONE for more details.

This method must only be called if COMMAND_GET_TIMELINE is available.

getNextWindowIndex

@UnstableApi
abstract int getNextWindowIndex()

getPlayWhenReady

abstract boolean getPlayWhenReady()

Whether playback will proceed when getPlaybackState == STATE_READY.

Returns
boolean

Whether playback will proceed when ready.

getPlaybackParameters

abstract PlaybackParameters getPlaybackParameters()

Returns the currently active playback parameters.

getPlaybackState

@Player.State
abstract int getPlaybackState()

Returns the current playback state of the player.

Returns
int

The current playback state.

getPlaybackSuppressionReason

@Player.PlaybackSuppressionReason
abstract int getPlaybackSuppressionReason()

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

Returns
int

The current PlaybackSuppressionReason.

getPlayerError

abstract @Nullable PlaybackException 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
@Nullable PlaybackException

The error, or null.

See also
onPlayerError

getPlaylistMetadata

abstract MediaMetadata getPlaylistMetadata()

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

This method must only be called if COMMAND_GET_METADATA is available.

getPreviousMediaItemIndex

abstract int getPreviousMediaItemIndex()

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. Returns INDEX_UNSET if hasPreviousMediaItem is false.

Note: When the repeat mode is REPEAT_MODE_ONE, this method behaves the same as when the current repeat mode is REPEAT_MODE_OFF. See REPEAT_MODE_ONE for more details.

This method must only be called if COMMAND_GET_TIMELINE is available.

getPreviousWindowIndex

@UnstableApi
abstract int getPreviousWindowIndex()

getRepeatMode

@Player.RepeatMode
abstract int getRepeatMode()

Returns the current RepeatMode used for playback.

Returns
int

The current repeat mode.

getSeekBackIncrement

abstract long getSeekBackIncrement()

Returns the seekBack increment.

Returns
long

The seek back increment, in milliseconds.

getSeekForwardIncrement

abstract long getSeekForwardIncrement()

Returns the seekForward increment.

Returns
long

The seek forward increment, in milliseconds.

getShuffleModeEnabled

abstract boolean getShuffleModeEnabled()

Returns whether shuffling of media items is enabled.

getSurfaceSize

@UnstableApi
abstract Size getSurfaceSize()

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

getTotalBufferedDuration

abstract long getTotalBufferedDuration()

Returns an estimate of the total buffered duration from the current position, in milliseconds. This includes pre-buffered data for subsequent ads and media items.

This method must only be called if COMMAND_GET_CURRENT_MEDIA_ITEM is available.

getTrackSelectionParameters

abstract TrackSelectionParameters getTrackSelectionParameters()

Returns the parameters constraining the track selection.

getVideoSize

abstract VideoSize getVideoSize()

Gets the size of the video.

The video's width and height are 0 if there is no supported video track or its size has not been determined yet.

getVolume

abstract @FloatRange(from = 0, to = 1.0) float getVolume()

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

This method must only be called if COMMAND_GET_VOLUME is available.

Returns
@FloatRange(from = 0, to = 1.0) float

The linear gain applied to all audio channels.

See also
onVolumeChanged

hasNext

@UnstableApi
abstract boolean hasNext()

hasNextMediaItem

abstract boolean hasNextMediaItem()

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

Note: When the repeat mode is REPEAT_MODE_ONE, this method behaves the same as when the current repeat mode is REPEAT_MODE_OFF. See REPEAT_MODE_ONE for more details.

This method must only be called if COMMAND_GET_TIMELINE is available.

hasNextWindow

@UnstableApi
abstract boolean hasNextWindow()

hasPreviousMediaItem

abstract boolean hasPreviousMediaItem()

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

Note: When the repeat mode is REPEAT_MODE_ONE, this method behaves the same as when the current repeat mode is REPEAT_MODE_OFF. See REPEAT_MODE_ONE for more details.

This method must only be called if COMMAND_GET_TIMELINE is available.

increaseDeviceVolume

abstract void increaseDeviceVolume()

increaseDeviceVolume

abstract void increaseDeviceVolume(@C.VolumeFlags int flags)

Increases the volume of the device.

The getDeviceVolume device volume cannot be increased above maxVolume, if defined.

Note that this method affects the device volume. To change the volume of the current stream only, use setVolume.

This method must only be called if COMMAND_ADJUST_DEVICE_VOLUME_WITH_FLAGS is available.

Parameters
@C.VolumeFlags int flags

Either 0 or a bitwise combination of one or more C.VolumeFlags.

isCommandAvailable

abstract boolean isCommandAvailable(@Player.Command int command)

Returns whether the provided Command is available.

This method does not execute the command.

Parameters
@Player.Command int command

A Command.

Returns
boolean

Whether the Command is available.

isCurrentMediaItemDynamic

abstract boolean isCurrentMediaItemDynamic()

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

This method must only be called if COMMAND_GET_CURRENT_MEDIA_ITEM is available.

See also
isDynamic

isCurrentMediaItemLive

abstract boolean isCurrentMediaItemLive()

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

This method must only be called if COMMAND_GET_CURRENT_MEDIA_ITEM is available.

See also
isLive

isCurrentMediaItemSeekable

abstract boolean isCurrentMediaItemSeekable()

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

This method must only be called if COMMAND_GET_CURRENT_MEDIA_ITEM is available.

See also
isSeekable

isCurrentWindowDynamic

@UnstableApi
abstract boolean isCurrentWindowDynamic()

isCurrentWindowLive

@UnstableApi
abstract boolean isCurrentWindowLive()

isCurrentWindowSeekable

@UnstableApi
abstract boolean isCurrentWindowSeekable()

isDeviceMuted

abstract boolean isDeviceMuted()

Gets whether the device is muted or not.

Note that this method returns the mute state of the device. To check if the current stream is muted, use getVolume() == 0.

This method must only be called if COMMAND_GET_DEVICE_VOLUME is available.

isLoading

abstract boolean isLoading()

Whether the player is currently loading the source.

Returns
boolean

Whether the player is currently loading the source.

isPlaying

abstract boolean isPlaying()

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

If false, then at least one of the following is true:

Returns
boolean

Whether the player is playing.

isPlayingAd

abstract boolean isPlayingAd()

Returns whether the player is currently playing an ad.

This method must only be called if COMMAND_GET_CURRENT_MEDIA_ITEM is available.

moveMediaItem

abstract void moveMediaItem(int currentIndex, int newIndex)

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

This method must only be called if COMMAND_CHANGE_MEDIA_ITEMS is available.

Parameters
int currentIndex

The current index of the media item to move. If the index is larger than the size of the playlist, the request is ignored.

int newIndex

The new index of the media item. If the new index is larger than the size of the playlist the item is moved to the end of the playlist.

moveMediaItems

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

Moves the media item range to the new index.

This method must only be called if COMMAND_CHANGE_MEDIA_ITEMS is available.

Parameters
int fromIndex

The start of the range to move. If the index is larger than the size of the playlist, the request is ignored.

int toIndex

The first item not to be included in the range (exclusive). If the index is larger than the size of the playlist, items up to the end of the playlist are moved.

int newIndex

The new index of the first media item of the range. If the new index is larger than the size of the remaining playlist after removing the range, the range is moved to the end of the playlist.

next

@UnstableApi
abstract void next()

pause

abstract void pause()

Pauses playback. Equivalent to setPlayWhenReady(false).

This method must only be called if COMMAND_PLAY_PAUSE is available.

play

abstract void play()

Resumes playback as soon as getPlaybackState == STATE_READY. Equivalent to setPlayWhenReady(true).

This method must only be called if COMMAND_PLAY_PAUSE is available.

prepare

abstract void prepare()

Prepares the player.

This method must only be called if COMMAND_PREPARE is available.

This will move the player out of idle state and the player will start loading media and acquire resources needed for playback.

release

abstract void release()

Releases the player. This method must be called when the player is no longer required. The player must not be used after calling this method.

This method must only be called if COMMAND_RELEASE is available.

removeListener

abstract void removeListener(Player.Listener listener)

Unregister a listener registered through addListener. The listener will no longer receive events.

Parameters
Player.Listener listener

The listener to unregister.

removeMediaItem

abstract void removeMediaItem(int index)

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

This method must only be called if COMMAND_CHANGE_MEDIA_ITEMS is available.

Parameters
int index

The index at which to remove the media item. If the index is larger than the size of the playlist, the request is ignored.

removeMediaItems

abstract void removeMediaItems(int fromIndex, int toIndex)

Removes a range of media items from the playlist.

This method must only be called if COMMAND_CHANGE_MEDIA_ITEMS is available.

Parameters
int fromIndex

The index at which to start removing media items. If the index is larger than the size of the playlist, the request is ignored.

int toIndex

The index of the first item to be kept (exclusive). If the index is larger than the size of the playlist, media items up to the end of the playlist are removed.

replaceMediaItem

abstract void replaceMediaItem(int index, MediaItem mediaItem)

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

Parameters
int index

The index at which to replace the media item. If the index is larger than the size of the playlist, the request is ignored.

MediaItem mediaItem

The new MediaItem.

replaceMediaItems

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

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

Parameters
int fromIndex

The start of the range. If the index is larger than the size of the playlist, the request is ignored.

int toIndex

The first item not to be included in the range (exclusive). If the index is larger than the size of the playlist, items up to the end of the playlist are replaced.

List<MediaItem> mediaItems

The media items to replace the range with.

seekBack

abstract void seekBack()

Seeks back in the current MediaItem by getSeekBackIncrement milliseconds.

This method must only be called if COMMAND_SEEK_BACK is available.

seekForward

abstract void seekForward()

Seeks forward in the current MediaItem by getSeekForwardIncrement milliseconds.

This method must only be called if COMMAND_SEEK_FORWARD is available.

seekTo

abstract void seekTo(long positionMs)

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

This method must only be called if COMMAND_SEEK_IN_CURRENT_MEDIA_ITEM is available.

Parameters
long positionMs

The seek position in the current MediaItem, or TIME_UNSET to seek to the media item's default position.

seekTo

abstract void seekTo(int mediaItemIndex, long positionMs)

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

This method must only be called if COMMAND_SEEK_TO_MEDIA_ITEM is available.

Parameters
int mediaItemIndex

The index of the MediaItem. If the index is larger than the size of the playlist, the request is ignored.

long positionMs

The seek position in the specified MediaItem, or TIME_UNSET to seek to the media item's default position.

seekToDefaultPosition

abstract void seekToDefaultPosition()

Seeks to the default position associated with the current MediaItem. The position can depend on the type of media being played. For live streams it will typically be the live edge. For other streams it will typically be the start.

This method must only be called if COMMAND_SEEK_TO_DEFAULT_POSITION is available.

seekToDefaultPosition

abstract void seekToDefaultPosition(int mediaItemIndex)

Seeks to the default position associated with the specified MediaItem. The position can depend on the type of media being played. For live streams it will typically be the live edge. For other streams it will typically be the start.

This method must only be called if COMMAND_SEEK_TO_MEDIA_ITEM is available.

Parameters
int mediaItemIndex

The index of the MediaItem whose associated default position should be seeked to. If the index is larger than the size of the playlist, the request is ignored.

seekToNext

abstract void seekToNext()

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

  • If the timeline is empty or seeking is not possible, does nothing.
  • Otherwise, if a next media item exists, seeks to the default position of the next MediaItem.
  • Otherwise, if the current MediaItem is live and has not ended, seeks to the live edge of the current MediaItem.
  • Otherwise, does nothing.

This method must only be called if COMMAND_SEEK_TO_NEXT is available.

seekToNextMediaItem

abstract void seekToNextMediaItem()

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

Note: When the repeat mode is REPEAT_MODE_ONE, this method behaves the same as when the current repeat mode is REPEAT_MODE_OFF. See REPEAT_MODE_ONE for more details.

This method must only be called if COMMAND_SEEK_TO_NEXT_MEDIA_ITEM is available.

seekToNextWindow

@UnstableApi
abstract void seekToNextWindow()

seekToPrevious

abstract void seekToPrevious()

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

This method must only be called if COMMAND_SEEK_TO_PREVIOUS is available.

seekToPreviousMediaItem

abstract void seekToPreviousMediaItem()

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

Note: When the repeat mode is REPEAT_MODE_ONE, this method behaves the same as when the current repeat mode is REPEAT_MODE_OFF. See REPEAT_MODE_ONE for more details.

This method must only be called if COMMAND_SEEK_TO_PREVIOUS_MEDIA_ITEM is available.

seekToPreviousWindow

@UnstableApi
abstract void seekToPreviousWindow()

setAudioAttributes

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

setDeviceMuted

abstract void setDeviceMuted(boolean muted)

setDeviceMuted

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

Sets the mute state of the device.

Note that this method affects the device volume. To mute just the current stream, use setVolume(0) instead.

This method must only be called if COMMAND_ADJUST_DEVICE_VOLUME_WITH_FLAGS is available.

Parameters
boolean muted

Whether to set the device to be muted or not

@C.VolumeFlags int flags

Either 0 or a bitwise combination of one or more C.VolumeFlags.

setDeviceVolume

abstract void setDeviceVolume(@IntRange(from = 0) int volume)

setDeviceVolume

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

Sets the volume of the device with volume flags.

Note that this method affects the device volume. To change the volume of the current stream only, use setVolume.

This method must only be called if COMMAND_SET_DEVICE_VOLUME_WITH_FLAGS is available.

Parameters
@IntRange(from = 0) int volume

The volume to set.

@C.VolumeFlags int flags

Either 0 or a bitwise combination of one or more C.VolumeFlags.

setMediaItem

abstract void setMediaItem(MediaItem mediaItem)

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

To replace a media item (possibly seamlessly) without clearing the playlist, use replaceMediaItem.

This method must only be called if COMMAND_SET_MEDIA_ITEM is available.

Parameters
MediaItem mediaItem

The new MediaItem.

setMediaItem

abstract void setMediaItem(MediaItem mediaItem, boolean resetPosition)

Clears the playlist and adds the specified MediaItem.

To replace a media item (possibly seamlessly) without clearing the playlist, use replaceMediaItem.

This method must only be called if COMMAND_SET_MEDIA_ITEM is available.

Parameters
MediaItem mediaItem

The new MediaItem.

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.

setMediaItem

abstract void setMediaItem(MediaItem mediaItem, long startPositionMs)

Clears the playlist and adds the specified MediaItem.

To replace a media item (possibly seamlessly) without clearing the playlist, use replaceMediaItem.

This method must only be called if COMMAND_SET_MEDIA_ITEM is available.

Parameters
MediaItem mediaItem

The new MediaItem.

long startPositionMs

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

setMediaItems

abstract void setMediaItems(List<MediaItem> mediaItems)

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

To replace a span of media items (possibly seamlessly) without clearing the playlist, use replaceMediaItems.

This method must only be called if COMMAND_CHANGE_MEDIA_ITEMS is available.

Parameters
List<MediaItem> mediaItems

The new media items.

setMediaItems

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

Clears the playlist and adds the specified media items.

To replace a span of media items (possibly seamlessly) without clearing the playlist, use replaceMediaItems.

This method must only be called if COMMAND_CHANGE_MEDIA_ITEMS is available.

Parameters
List<MediaItem> mediaItems

The new media items.

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.

setMediaItems

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

Clears the playlist and adds the specified media items.

To replace a span of media items (possibly seamlessly) without clearing the playlist, use replaceMediaItems.

This method must only be called if COMMAND_CHANGE_MEDIA_ITEMS is available.

Parameters
List<MediaItem> mediaItems

The new media items.

int startIndex

The MediaItem 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 MediaItem is used. In any case, if startIndex is set to INDEX_UNSET, this parameter is ignored and the position is not reset at all.

Throws
androidx.media3.common.IllegalSeekPositionException

If the provided startIndex is not within the bounds of the list of media items.

setPlayWhenReady

abstract void setPlayWhenReady(boolean playWhenReady)

Sets whether playback should proceed when getPlaybackState == STATE_READY.

If the player is already in the ready state then this method pauses and resumes playback.

This method must only be called if COMMAND_PLAY_PAUSE is available.

Parameters
boolean playWhenReady

Whether playback should proceed when ready.

setPlaybackParameters

abstract void setPlaybackParameters(PlaybackParameters playbackParameters)

Attempts to set the playback parameters. Passing DEFAULT resets the player to the default, which means there is no speed or pitch adjustment.

Playback parameters changes may cause the player to buffer. onPlaybackParametersChanged will be called whenever the currently active playback parameters change.

This method must only be called if COMMAND_SET_SPEED_AND_PITCH is available.

Parameters
PlaybackParameters playbackParameters

The playback parameters.

setPlaybackSpeed

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

Changes the rate at which playback occurs. The pitch is not changed.

This is equivalent to setPlaybackParameters(getPlaybackParameters().withSpeed(speed)).

This method must only be called if COMMAND_SET_SPEED_AND_PITCH is available.

Parameters
@FloatRange(from = 0, fromInclusive = false) float speed

The linear factor by which playback will be sped up. Must be higher than 0. 1 is normal speed, 2 is twice as fast, 0.5 is half normal speed.

setPlaylistMetadata

abstract void setPlaylistMetadata(MediaMetadata mediaMetadata)

Sets the playlist MediaMetadata.

This method must only be called if COMMAND_SET_PLAYLIST_METADATA is available.

setRepeatMode

abstract void setRepeatMode(@Player.RepeatMode int repeatMode)

Sets the RepeatMode to be used for playback.

This method must only be called if COMMAND_SET_REPEAT_MODE is available.

Parameters
@Player.RepeatMode int repeatMode

The repeat mode.

setShuffleModeEnabled

abstract void setShuffleModeEnabled(boolean shuffleModeEnabled)

Sets whether shuffling of media items is enabled.

This method must only be called if COMMAND_SET_SHUFFLE_MODE is available.

Parameters
boolean shuffleModeEnabled

Whether shuffling is enabled.

setTrackSelectionParameters

abstract void setTrackSelectionParameters(TrackSelectionParameters parameters)

Sets the parameters constraining the track selection.

Unsupported parameters will be silently ignored.

Use getTrackSelectionParameters to retrieve the current parameters. For example, the following snippet restricts video to SD whilst keep other track selection parameters unchanged:

player.setTrackSelectionParameters(
  player.getTrackSelectionParameters()
        .buildUpon()
        .setMaxVideoSizeSd()
        .build())

This method must only be called if COMMAND_SET_TRACK_SELECTION_PARAMETERS is available.

setVideoSurface

abstract void setVideoSurface(@Nullable Surface surface)

Sets the Surface onto which video will be rendered. The caller is responsible for tracking the lifecycle of the surface, and must clear the surface by calling setVideoSurface(null) if the surface is destroyed.

If the surface is held by a SurfaceView, TextureView or then it's recommended to use setVideoSurfaceView, setVideoTextureView or setVideoSurfaceHolder rather than this method, since passing the holder allows the player to track the lifecycle of the surface automatically.

This method must only be called if COMMAND_SET_VIDEO_SURFACE is available.

Parameters
@Nullable Surface surface

The Surface.

setVideoSurfaceHolder

abstract void setVideoSurfaceHolder(@Nullable SurfaceHolder surfaceHolder)

Sets the SurfaceHolder that holds the Surface onto which video will be rendered. The player will track the lifecycle of the surface automatically.

The thread that calls the SurfaceHolder.Callback methods must be the thread associated with getApplicationLooper.

This method must only be called if COMMAND_SET_VIDEO_SURFACE is available.

Parameters
@Nullable SurfaceHolder surfaceHolder

The surface holder.

setVideoSurfaceView

abstract void setVideoSurfaceView(@Nullable SurfaceView surfaceView)

Sets the SurfaceView onto which video will be rendered. The player will track the lifecycle of the surface automatically.

The thread that calls the SurfaceHolder.Callback methods must be the thread associated with getApplicationLooper.

This method must only be called if COMMAND_SET_VIDEO_SURFACE is available.

Parameters
@Nullable SurfaceView surfaceView

The surface view.

setVideoTextureView

abstract void setVideoTextureView(@Nullable TextureView textureView)

Sets the TextureView onto which video will be rendered. The player will track the lifecycle of the surface automatically.

Consider using SurfaceView via setVideoSurfaceView instead of . SurfaceView generally causes lower battery consumption, and has better handling for HDR and secure content. See Choosing a surface type for more information.

The thread that calls the TextureView.SurfaceTextureListener methods must be the thread associated with getApplicationLooper.

This method must only be called if COMMAND_SET_VIDEO_SURFACE is available.

Parameters
@Nullable TextureView textureView

The texture view.

setVolume

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.

This method must only be called if COMMAND_SET_VOLUME is available.

Parameters
@FloatRange(from = 0, to = 1.0) float volume

Linear output gain to apply to all audio channels.

stop

abstract void stop()

Stops playback without resetting the playlist. Use pause rather than this method if the intention is to pause playback.

Calling this method will cause the playback state to transition to STATE_IDLE and the player will release the loaded media and resources required for playback. The player instance can still be used by calling prepare again, and release must still be called on the player if it's no longer required.

Calling this method does not clear the playlist, reset the playback position or the playback error.

This method must only be called if COMMAND_STOP is available.

Extension functions

PlayerExtensionsKt.listen

@UnstableApi
default final @NonNull Void PlayerExtensionsKt.listen(
    @NonNull Player receiver,
    @ExtensionFunctionType @NonNull Function2<@NonNull Player, @NonNull Player.EventsUnit> onEvents
)

Continuously listens to the Player.Listener.onEvents callback, passing the received Player.Events to the provided onEvents function.

This function can be called from any thread. The onEvents function will be invoked on the thread associated with Player.getApplicationLooper.

If, during the execution of onEvents, an exception is thrown, the coroutine corresponding to listening to the Player will be terminated. Any used resources will be cleaned up (e.g. removing of the listeners) and exception will be re-thrown right after the last suspension point.

Parameters
@ExtensionFunctionType @NonNull Function2<@NonNull Player, @NonNull Player.EventsUnit> onEvents

The function to handle player events.

Returns
@NonNull Void

Nothing This function never returns normally. It will either continue indefinitely or terminate due to an exception or cancellation.