Interface Player
-
- All Known Subinterfaces:
ExoPlayer
- All Known Implementing Classes:
BasePlayer,CastPlayer,ForwardingPlayer,SimpleExoPlayer,StubExoPlayer,StubPlayer
public interface PlayerA media player interface defining traditional high-level functionality, such as the ability to play, pause, seek and query properties of the currently playing media.This interface includes some convenience methods that can be implemented by calling other methods in the interface.
BasePlayerimplements these convenience methods so inheritingBasePlayeris recommended when implementing the interface so that only the minimal set of required methods can be implemented.Some important properties of media players that implement this interface are:
- They can provide a
Timelinerepresenting the structure of the media being played, which can be obtained by callinggetCurrentTimeline(). - They can provide a
TracksInfodefining the currently available tracks and which are selected to be rendered, which can be obtained by callinggetCurrentTracksInfo().
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interfacePlayer.CommandCommands that can be executed on aPlayer.static classPlayer.CommandsA set ofcommands.static interfacePlayer.DiscontinuityReasonReasons for position discontinuities.static interfacePlayer.EventEvents that can be reported viaPlayer.Listener.onEvents(Player, Events).static interfacePlayer.EventListenerDeprecated.UsePlayer.Listener.static classPlayer.EventsA set ofevents.static interfacePlayer.ListenerListener of all changes in the Player.static interfacePlayer.MediaItemTransitionReasonReasons for media item transitions.static interfacePlayer.PlaybackSuppressionReasonReason why playback is suppressed even thoughgetPlayWhenReady()istrue.static interfacePlayer.PlayWhenReadyChangeReasonReasons forplayWhenReadychanges.static classPlayer.PositionInfoPosition info describing a playback position involved in a discontinuity.static interfacePlayer.RepeatModeRepeat modes for playback.static interfacePlayer.StatePlayback state.static interfacePlayer.TimelineChangeReasonReasons for timeline changes.
-
Field Summary
Fields Modifier and Type Field Description static intCOMMAND_ADJUST_DEVICE_VOLUMECommand to increase and decrease the device volume and mute it.static intCOMMAND_CHANGE_MEDIA_ITEMSCommand to change theMediaItemsin the playlist.static intCOMMAND_GET_AUDIO_ATTRIBUTESCommand to get the player currentAudioAttributes.static intCOMMAND_GET_CURRENT_MEDIA_ITEMCommand to get the currently playingMediaItem.static intCOMMAND_GET_DEVICE_VOLUMECommand to get the device volume and whether it is muted.static intCOMMAND_GET_MEDIA_ITEMS_METADATACommand to get theMediaItemsmetadata.static intCOMMAND_GET_TEXTCommand to get the text that should currently be displayed by the player.static intCOMMAND_GET_TIMELINECommand to get the information about the current timeline.static intCOMMAND_GET_TRACK_INFOSCommand to get track infos.static intCOMMAND_GET_VOLUMECommand to get the player volume.static intCOMMAND_INVALIDRepresents an invalidPlayer.Command.static intCOMMAND_PLAY_PAUSECommand to start, pause or resume playback.static intCOMMAND_PREPARECommand to prepare the player.static intCOMMAND_SEEK_BACKCommand to seek back by a fixed increment into the currentMediaItem.static intCOMMAND_SEEK_FORWARDCommand to seek forward by a fixed increment into the currentMediaItem.static intCOMMAND_SEEK_IN_CURRENT_MEDIA_ITEMCommand to seek anywhere into the currentMediaItem.static intCOMMAND_SEEK_IN_CURRENT_WINDOWDeprecated.UseCOMMAND_SEEK_IN_CURRENT_MEDIA_ITEMinstead.static intCOMMAND_SEEK_TO_DEFAULT_POSITIONCommand to seek to the default position of the currentMediaItem.static intCOMMAND_SEEK_TO_MEDIA_ITEMCommand to seek anywhere in anyMediaItem.static intCOMMAND_SEEK_TO_NEXTCommand to seek to a later position in the current or nextMediaItem.static intCOMMAND_SEEK_TO_NEXT_MEDIA_ITEMCommand to seek to the default position of the nextMediaItem.static intCOMMAND_SEEK_TO_NEXT_WINDOWDeprecated.UseCOMMAND_SEEK_TO_NEXT_MEDIA_ITEMinstead.static intCOMMAND_SEEK_TO_PREVIOUSCommand to seek to an earlier position in the current or previousMediaItem.static intCOMMAND_SEEK_TO_PREVIOUS_MEDIA_ITEMCommand to seek to the default position of the previousMediaItem.static intCOMMAND_SEEK_TO_PREVIOUS_WINDOWDeprecated.UseCOMMAND_SEEK_TO_PREVIOUS_MEDIA_ITEMinstead.static intCOMMAND_SEEK_TO_WINDOWDeprecated.UseCOMMAND_SEEK_TO_MEDIA_ITEMinstead.static intCOMMAND_SET_DEVICE_VOLUMECommand to set the device volume and mute it.static intCOMMAND_SET_MEDIA_ITEMS_METADATACommand to set theMediaItemsmetadata.static intCOMMAND_SET_REPEAT_MODECommand to set the repeat mode.static intCOMMAND_SET_SHUFFLE_MODECommand to enable shuffling.static intCOMMAND_SET_SPEED_AND_PITCHCommand to set the playback speed and pitch.static intCOMMAND_SET_TRACK_SELECTION_PARAMETERSCommand to set the player's track selection parameters.static intCOMMAND_SET_VIDEO_SURFACECommand to set and clear the surface on which to render the video.static intCOMMAND_SET_VOLUMECommand to set the player volume.static intCOMMAND_STOPCommand to stop playback or release the player.static intDISCONTINUITY_REASON_AUTO_TRANSITIONAutomatic playback transition from one period in the timeline to the next.static intDISCONTINUITY_REASON_INTERNALDiscontinuity introduced internally (e.g.static intDISCONTINUITY_REASON_REMOVEDiscontinuity caused by the removal of the current period from theTimeline.static intDISCONTINUITY_REASON_SEEKSeek within the current period or to another period.static intDISCONTINUITY_REASON_SEEK_ADJUSTMENTSeek adjustment due to being unable to seek to the requested position or because the seek was permitted to be inexact.static intDISCONTINUITY_REASON_SKIPDiscontinuity introduced by a skipped period (for instance a skipped ad).static intEVENT_AVAILABLE_COMMANDS_CHANGEDisCommandAvailable(int)changed for at least onePlayer.Command.static intEVENT_IS_LOADING_CHANGEDisLoading()()} changed.static intEVENT_IS_PLAYING_CHANGEDisPlaying()changed.static intEVENT_MAX_SEEK_TO_PREVIOUS_POSITION_CHANGEDgetMaxSeekToPreviousPosition()changed.static intEVENT_MEDIA_ITEM_TRANSITIONgetCurrentMediaItem()changed or the player started repeating the current item.static intEVENT_MEDIA_METADATA_CHANGEDgetMediaMetadata()changed.static intEVENT_PLAY_WHEN_READY_CHANGEDgetPlayWhenReady()changed.static intEVENT_PLAYBACK_PARAMETERS_CHANGEDgetPlaybackParameters()changed.static intEVENT_PLAYBACK_STATE_CHANGEDgetPlaybackState()changed.static intEVENT_PLAYBACK_SUPPRESSION_REASON_CHANGEDgetPlaybackSuppressionReason()changed.static intEVENT_PLAYER_ERRORgetPlayerError()changed.static intEVENT_PLAYLIST_METADATA_CHANGEDgetPlaylistMetadata()changed.static intEVENT_POSITION_DISCONTINUITYA position discontinuity occurred.static intEVENT_REPEAT_MODE_CHANGEDgetRepeatMode()changed.static intEVENT_SEEK_BACK_INCREMENT_CHANGEDgetSeekBackIncrement()changed.static intEVENT_SEEK_FORWARD_INCREMENT_CHANGEDgetSeekForwardIncrement()changed.static intEVENT_SHUFFLE_MODE_ENABLED_CHANGEDgetShuffleModeEnabled()changed.static intEVENT_TIMELINE_CHANGEDgetCurrentTimeline()changed.static intEVENT_TRACK_SELECTION_PARAMETERS_CHANGEDgetTrackSelectionParameters()changed.static intEVENT_TRACKS_CHANGEDgetCurrentTracksInfo()changed.static intMEDIA_ITEM_TRANSITION_REASON_AUTOPlayback has automatically transitioned to the next media item.static intMEDIA_ITEM_TRANSITION_REASON_PLAYLIST_CHANGEDThe current media item has changed because of a change in the playlist.static intMEDIA_ITEM_TRANSITION_REASON_REPEATThe media item has been repeated.static intMEDIA_ITEM_TRANSITION_REASON_SEEKA seek to another media item has occurred.static intPLAY_WHEN_READY_CHANGE_REASON_AUDIO_BECOMING_NOISYPlayback has been paused to avoid becoming noisy.static intPLAY_WHEN_READY_CHANGE_REASON_AUDIO_FOCUS_LOSSPlayback has been paused because of a loss of audio focus.static intPLAY_WHEN_READY_CHANGE_REASON_END_OF_MEDIA_ITEMPlayback has been paused at the end of a media item.static intPLAY_WHEN_READY_CHANGE_REASON_REMOTEPlayback has been started or paused because of a remote change.static intPLAY_WHEN_READY_CHANGE_REASON_USER_REQUESTPlayback has been started or paused by a call tosetPlayWhenReady(boolean).static intPLAYBACK_SUPPRESSION_REASON_NONEPlayback is not suppressed.static intPLAYBACK_SUPPRESSION_REASON_TRANSIENT_AUDIO_FOCUS_LOSSPlayback is suppressed due to transient audio focus loss.static intREPEAT_MODE_ALLRepeats the entire timeline infinitely.static intREPEAT_MODE_OFFNormal playback without repetition.static intREPEAT_MODE_ONERepeats the currently playingMediaIteminfinitely during ongoing playback.static intSTATE_BUFFERINGThe player is not able to immediately play the media, but is doing work toward being able to do so.static intSTATE_ENDEDThe player has finished playing the media.static intSTATE_IDLEThe player is idle, meaning it holds only limited resources.static intSTATE_READYThe player is able to immediately play from its current position.static intTIMELINE_CHANGE_REASON_PLAYLIST_CHANGEDTimeline changed as a result of a change of the playlist items or the order of the items.static intTIMELINE_CHANGE_REASON_SOURCE_UPDATETimeline changed as a result of a source update (e.g.
-
Method Summary
All Methods Instance Methods Abstract Methods Deprecated Methods Modifier and Type Method Description voidaddListener(Player.Listener listener)Registers a listener to receive all events from the player.voidaddMediaItem(int index, MediaItem mediaItem)Adds a media item at the given index of the playlist.voidaddMediaItem(MediaItem mediaItem)Adds a media item to the end of the playlist.voidaddMediaItems(int index, List<MediaItem> mediaItems)Adds a list of media items at the given index of the playlist.voidaddMediaItems(List<MediaItem> mediaItems)Adds a list of media items to the end of the playlist.booleancanAdvertiseSession()Returns whether the player can be used to advertise a media session.voidclearMediaItems()Clears the playlist.voidclearVideoSurface()voidclearVideoSurface(Surface surface)Clears theSurfaceonto which video is being rendered if it matches the one passed.voidclearVideoSurfaceHolder(SurfaceHolder surfaceHolder)Clears theSurfaceHolderthat holds theSurfaceonto which video is being rendered if it matches the one passed.voidclearVideoSurfaceView(SurfaceView surfaceView)Clears theSurfaceViewonto which video is being rendered if it matches the one passed.voidclearVideoTextureView(TextureView textureView)Clears theTextureViewonto which video is being rendered if it matches the one passed.voiddecreaseDeviceVolume()Decreases the volume of the device.LoopergetApplicationLooper()Returns theLooperassociated with the application thread that's used to access the player and on which player events are received.AudioAttributesgetAudioAttributes()Returns the attributes for audio playback.Player.CommandsgetAvailableCommands()Returns the player's currently availablePlayer.Commands.intgetBufferedPercentage()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.longgetBufferedPosition()Returns an estimate of the position in the current content or ad up to which data is buffered, in milliseconds.longgetContentBufferedPosition()IfisPlayingAd()returnstrue, returns an estimate of the content position in the current content up to which data is buffered, in milliseconds.longgetContentDuration()IfisPlayingAd()returnstrue, returns the duration of the current content in milliseconds, orC.TIME_UNSETif the duration is not known.longgetContentPosition()IfisPlayingAd()returnstrue, returns the content position that will be played once all ads in the ad group have finished playing, in milliseconds.intgetCurrentAdGroupIndex()IfisPlayingAd()returns true, returns the index of the ad group in the period currently being played.intgetCurrentAdIndexInAdGroup()IfisPlayingAd()returns true, returns the index of the ad in its ad group.List<Cue>getCurrentCues()Returns the currentCues.longgetCurrentLiveOffset()Returns the offset of the current playback position from the live edge in milliseconds, orC.TIME_UNSETif the currentMediaItemisCurrentMediaItemLive()isn't live} or the offset is unknown.ObjectgetCurrentManifest()Returns the current manifest.MediaItemgetCurrentMediaItem()Returns the currently playingMediaItem.intgetCurrentMediaItemIndex()Returns the index of the currentMediaItemin thetimeline, or the prospective index if thecurrent timelineis empty.intgetCurrentPeriodIndex()Returns the index of the period currently being played.longgetCurrentPosition()Returns the playback position in the current content or ad, in milliseconds, or the prospective position in milliseconds if thecurrent timelineis empty.TimelinegetCurrentTimeline()Returns the currentTimeline.TrackGroupArraygetCurrentTrackGroups()Deprecated.TrackSelectionArraygetCurrentTrackSelections()Deprecated.TracksInfogetCurrentTracksInfo()Returns the available tracks, as well as the tracks' support, type, and selection status.intgetCurrentWindowIndex()Deprecated.UsegetCurrentMediaItemIndex()instead.DeviceInfogetDeviceInfo()Gets the device information.intgetDeviceVolume()Gets the current volume of the device.longgetDuration()Returns the duration of the current content or ad in milliseconds, orC.TIME_UNSETif the duration is not known.longgetMaxSeekToPreviousPosition()Returns the maximum position for whichseekToPrevious()seeks to the previousMediaItem, in milliseconds.MediaItemgetMediaItemAt(int index)Returns theMediaItemat the given index.intgetMediaItemCount()Returns the number ofmedia itemsin the playlist.MediaMetadatagetMediaMetadata()Returns the current combinedMediaMetadata, orMediaMetadata.EMPTYif not supported.intgetNextMediaItemIndex()Returns the index of theMediaItemthat will be played ifseekToNextMediaItem()is called, which may depend on the current repeat mode and whether shuffle mode is enabled.intgetNextWindowIndex()Deprecated.UsegetNextMediaItemIndex()instead.PlaybackParametersgetPlaybackParameters()Returns the currently active playback parameters.@com.google.android.exoplayer2.Player.State intgetPlaybackState()Returns the currentplayback stateof the player.@com.google.android.exoplayer2.Player.PlaybackSuppressionReason intgetPlaybackSuppressionReason()Returns the reason why playback is suppressed even thoughgetPlayWhenReady()istrue, orPLAYBACK_SUPPRESSION_REASON_NONEif playback is not suppressed.PlaybackExceptiongetPlayerError()Returns the error that caused playback to fail.MediaMetadatagetPlaylistMetadata()Returns the playlistMediaMetadata, as set bysetPlaylistMetadata(MediaMetadata), orMediaMetadata.EMPTYif not supported.booleangetPlayWhenReady()Whether playback will proceed whengetPlaybackState()==STATE_READY.intgetPreviousMediaItemIndex()Returns the index of theMediaItemthat will be played ifseekToPreviousMediaItem()is called, which may depend on the current repeat mode and whether shuffle mode is enabled.intgetPreviousWindowIndex()Deprecated.UsegetPreviousMediaItemIndex()instead.@com.google.android.exoplayer2.Player.RepeatMode intgetRepeatMode()Returns the currentPlayer.RepeatModeused for playback.longgetSeekBackIncrement()Returns theseekBack()increment.longgetSeekForwardIncrement()Returns theseekForward()increment.booleangetShuffleModeEnabled()Returns whether shuffling of media items is enabled.longgetTotalBufferedDuration()Returns an estimate of the total buffered duration from the current position, in milliseconds.TrackSelectionParametersgetTrackSelectionParameters()Returns the parameters constraining the track selection.VideoSizegetVideoSize()Gets the size of the video.floatgetVolume()Returns the audio volume, with 0 being silence and 1 being unity gain (signal unchanged).booleanhasNext()Deprecated.UsehasNextMediaItem()instead.booleanhasNextMediaItem()Returns whether a nextMediaItemexists, which may depend on the current repeat mode and whether shuffle mode is enabled.booleanhasNextWindow()Deprecated.UsehasNextMediaItem()instead.booleanhasPrevious()Deprecated.UsehasPreviousMediaItem()instead.booleanhasPreviousMediaItem()Returns whether a previous media item exists, which may depend on the current repeat mode and whether shuffle mode is enabled.booleanhasPreviousWindow()Deprecated.UsehasPreviousMediaItem()instead.voidincreaseDeviceVolume()Increases the volume of the device.booleanisCommandAvailable(@com.google.android.exoplayer2.Player.Command int command)Returns whether the providedPlayer.Commandis available.booleanisCurrentMediaItemDynamic()booleanisCurrentMediaItemLive()booleanisCurrentMediaItemSeekable()booleanisCurrentWindowDynamic()Deprecated.UseisCurrentMediaItemDynamic()instead.booleanisCurrentWindowLive()Deprecated.UseisCurrentMediaItemLive()instead.booleanisCurrentWindowSeekable()Deprecated.UseisCurrentMediaItemSeekable()instead.booleanisDeviceMuted()Gets whether the device is muted or not.booleanisLoading()Whether the player is currently loading the source.booleanisPlaying()Returns whether the player is playing, i.e.booleanisPlayingAd()Returns whether the player is currently playing an ad.voidmoveMediaItem(int currentIndex, int newIndex)Moves the media item at the current index to the new index.voidmoveMediaItems(int fromIndex, int toIndex, int newIndex)Moves the media item range to the new index.voidnext()Deprecated.UseseekToNextMediaItem()instead.voidpause()Pauses playback.voidplay()Resumes playback as soon asgetPlaybackState()==STATE_READY.voidprepare()Prepares the player.voidprevious()Deprecated.UseseekToPreviousMediaItem()instead.voidrelease()Releases the player.voidremoveListener(Player.Listener listener)Unregister a listener registered throughaddListener(Listener).voidremoveMediaItem(int index)Removes the media item at the given index of the playlist.voidremoveMediaItems(int fromIndex, int toIndex)Removes a range of media items from the playlist.voidseekBack()Seeks back in the currentMediaItembygetSeekBackIncrement()milliseconds.voidseekForward()Seeks forward in the currentMediaItembygetSeekForwardIncrement()milliseconds.voidseekTo(int mediaItemIndex, long positionMs)Seeks to a position specified in milliseconds in the specifiedMediaItem.voidseekTo(long positionMs)Seeks to a position specified in milliseconds in the currentMediaItem.voidseekToDefaultPosition()Seeks to the default position associated with the currentMediaItem.voidseekToDefaultPosition(int mediaItemIndex)Seeks to the default position associated with the specifiedMediaItem.voidseekToNext()Seeks to a later position in the current or nextMediaItem(if available).voidseekToNextMediaItem()Seeks to the default position of the nextMediaItem, which may depend on the current repeat mode and whether shuffle mode is enabled.voidseekToNextWindow()Deprecated.UseseekToNextMediaItem()instead.voidseekToPrevious()Seeks to an earlier position in the current or previousMediaItem(if available).voidseekToPreviousMediaItem()Seeks to the default position of the previousMediaItem, which may depend on the current repeat mode and whether shuffle mode is enabled.voidseekToPreviousWindow()Deprecated.UseseekToPreviousMediaItem()instead.voidsetDeviceMuted(boolean muted)Sets the mute state of the device.voidsetDeviceVolume(int volume)Sets the volume of the device.voidsetMediaItem(MediaItem mediaItem)Clears the playlist, adds the specifiedMediaItemand resets the position to the default position.voidsetMediaItem(MediaItem mediaItem, boolean resetPosition)Clears the playlist and adds the specifiedMediaItem.voidsetMediaItem(MediaItem mediaItem, long startPositionMs)Clears the playlist and adds the specifiedMediaItem.voidsetMediaItems(List<MediaItem> mediaItems)Clears the playlist, adds the specifiedMediaItemsand resets the position to the default position.voidsetMediaItems(List<MediaItem> mediaItems, boolean resetPosition)Clears the playlist and adds the specifiedMediaItems.voidsetMediaItems(List<MediaItem> mediaItems, int startIndex, long startPositionMs)Clears the playlist and adds the specifiedMediaItems.voidsetPlaybackParameters(PlaybackParameters playbackParameters)Attempts to set the playback parameters.voidsetPlaybackSpeed(float speed)Changes the rate at which playback occurs.voidsetPlaylistMetadata(MediaMetadata mediaMetadata)Sets the playlistMediaMetadata.voidsetPlayWhenReady(boolean playWhenReady)Sets whether playback should proceed whengetPlaybackState()==STATE_READY.voidsetRepeatMode(@com.google.android.exoplayer2.Player.RepeatMode int repeatMode)Sets thePlayer.RepeatModeto be used for playback.voidsetShuffleModeEnabled(boolean shuffleModeEnabled)Sets whether shuffling of media items is enabled.voidsetTrackSelectionParameters(TrackSelectionParameters parameters)Sets the parameters constraining the track selection.voidsetVideoSurface(Surface surface)Sets theSurfaceonto which video will be rendered.voidsetVideoSurfaceHolder(SurfaceHolder surfaceHolder)Sets theSurfaceHolderthat holds theSurfaceonto which video will be rendered.voidsetVideoSurfaceView(SurfaceView surfaceView)Sets theSurfaceViewonto which video will be rendered.voidsetVideoTextureView(TextureView textureView)Sets theTextureViewonto which video will be rendered.voidsetVolume(float volume)Sets the audio volume, valid values are between 0 (silence) and 1 (unity gain, signal unchanged), inclusive.voidstop()Stops playback without resetting the playlist.voidstop(boolean reset)Deprecated.
-
-
-
Field Detail
-
STATE_IDLE
static final int STATE_IDLE
The player is idle, meaning it holds only limited resources. The player must bepreparedbefore it will play the media.- See Also:
- Constant Field Values
-
STATE_BUFFERING
static final int STATE_BUFFERING
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.- See Also:
- Constant Field Values
-
STATE_READY
static final int STATE_READY
The player is able to immediately play from its current position. The player will be playing ifgetPlayWhenReady()is true, and paused otherwise.- See Also:
- Constant Field Values
-
STATE_ENDED
static final int STATE_ENDED
The player has finished playing the media.- See Also:
- Constant Field Values
-
PLAY_WHEN_READY_CHANGE_REASON_USER_REQUEST
static final int PLAY_WHEN_READY_CHANGE_REASON_USER_REQUEST
Playback has been started or paused by a call tosetPlayWhenReady(boolean).- See Also:
- Constant Field Values
-
PLAY_WHEN_READY_CHANGE_REASON_AUDIO_FOCUS_LOSS
static final int PLAY_WHEN_READY_CHANGE_REASON_AUDIO_FOCUS_LOSS
Playback has been paused because of a loss of audio focus.- See Also:
- Constant Field Values
-
PLAY_WHEN_READY_CHANGE_REASON_AUDIO_BECOMING_NOISY
static final int PLAY_WHEN_READY_CHANGE_REASON_AUDIO_BECOMING_NOISY
Playback has been paused to avoid becoming noisy.- See Also:
- Constant Field Values
-
PLAY_WHEN_READY_CHANGE_REASON_REMOTE
static final int PLAY_WHEN_READY_CHANGE_REASON_REMOTE
Playback has been started or paused because of a remote change.- See Also:
- Constant Field Values
-
PLAY_WHEN_READY_CHANGE_REASON_END_OF_MEDIA_ITEM
static final int PLAY_WHEN_READY_CHANGE_REASON_END_OF_MEDIA_ITEM
Playback has been paused at the end of a media item.- See Also:
- Constant Field Values
-
PLAYBACK_SUPPRESSION_REASON_NONE
static final int PLAYBACK_SUPPRESSION_REASON_NONE
Playback is not suppressed.- See Also:
- Constant Field Values
-
PLAYBACK_SUPPRESSION_REASON_TRANSIENT_AUDIO_FOCUS_LOSS
static final int PLAYBACK_SUPPRESSION_REASON_TRANSIENT_AUDIO_FOCUS_LOSS
Playback is suppressed due to transient audio focus loss.- See Also:
- Constant Field Values
-
REPEAT_MODE_OFF
static final int REPEAT_MODE_OFF
Normal playback without repetition. "Previous" and "Next" actions move to the previous and nextMediaItemrespectively, and do nothing when there is no previous or nextMediaItemto move to.- See Also:
- Constant Field Values
-
REPEAT_MODE_ONE
static final int REPEAT_MODE_ONE
Repeats the currently playingMediaIteminfinitely during ongoing playback. "Previous" and "Next" actions behave as they do inREPEAT_MODE_OFF, moving to the previous and nextMediaItemrespectively, and doing nothing when there is no previous or nextMediaItemto move to.- See Also:
- Constant Field Values
-
REPEAT_MODE_ALL
static final int REPEAT_MODE_ALL
Repeats the entire timeline infinitely. "Previous" and "Next" actions behave as they do inREPEAT_MODE_OFF, but with looping at the ends so that "Previous" when playing the firstMediaItemwill move to the lastMediaItem, and "Next" when playing the lastMediaItemwill move to the firstMediaItem.- See Also:
- Constant Field Values
-
DISCONTINUITY_REASON_AUTO_TRANSITION
static final int DISCONTINUITY_REASON_AUTO_TRANSITION
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).
- See Also:
- Constant Field Values
-
DISCONTINUITY_REASON_SEEK
static final int DISCONTINUITY_REASON_SEEK
Seek within the current period or to another period.- See Also:
- Constant Field Values
-
DISCONTINUITY_REASON_SEEK_ADJUSTMENT
static final int DISCONTINUITY_REASON_SEEK_ADJUSTMENT
Seek adjustment due to being unable to seek to the requested position or because the seek was permitted to be inexact.- See Also:
- Constant Field Values
-
DISCONTINUITY_REASON_SKIP
static final int DISCONTINUITY_REASON_SKIP
Discontinuity introduced by a skipped period (for instance a skipped ad).- See Also:
- Constant Field Values
-
DISCONTINUITY_REASON_REMOVE
static final int DISCONTINUITY_REASON_REMOVE
Discontinuity caused by the removal of the current period from theTimeline.- See Also:
- Constant Field Values
-
DISCONTINUITY_REASON_INTERNAL
static final int DISCONTINUITY_REASON_INTERNAL
Discontinuity introduced internally (e.g. by the source).- See Also:
- Constant Field Values
-
TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED
static final int TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED
Timeline changed as a result of a change of the playlist items or the order of the items.- See Also:
- Constant Field Values
-
TIMELINE_CHANGE_REASON_SOURCE_UPDATE
static final int TIMELINE_CHANGE_REASON_SOURCE_UPDATE
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).
- See Also:
- Constant Field Values
-
MEDIA_ITEM_TRANSITION_REASON_REPEAT
static final int MEDIA_ITEM_TRANSITION_REASON_REPEAT
The media item has been repeated.- See Also:
- Constant Field Values
-
MEDIA_ITEM_TRANSITION_REASON_AUTO
static final int MEDIA_ITEM_TRANSITION_REASON_AUTO
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).
- See Also:
- Constant Field Values
-
MEDIA_ITEM_TRANSITION_REASON_SEEK
static final int MEDIA_ITEM_TRANSITION_REASON_SEEK
A seek to another media item has occurred.- See Also:
- Constant Field Values
-
MEDIA_ITEM_TRANSITION_REASON_PLAYLIST_CHANGED
static final int MEDIA_ITEM_TRANSITION_REASON_PLAYLIST_CHANGED
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.- See Also:
- Constant Field Values
-
EVENT_TIMELINE_CHANGED
static final int EVENT_TIMELINE_CHANGED
getCurrentTimeline()changed.- See Also:
- Constant Field Values
-
EVENT_MEDIA_ITEM_TRANSITION
static final int EVENT_MEDIA_ITEM_TRANSITION
getCurrentMediaItem()changed or the player started repeating the current item.- See Also:
- Constant Field Values
-
EVENT_TRACKS_CHANGED
static final int EVENT_TRACKS_CHANGED
getCurrentTracksInfo()changed.- See Also:
- Constant Field Values
-
EVENT_IS_LOADING_CHANGED
static final int EVENT_IS_LOADING_CHANGED
isLoading()()} changed.- See Also:
- Constant Field Values
-
EVENT_PLAYBACK_STATE_CHANGED
static final int EVENT_PLAYBACK_STATE_CHANGED
getPlaybackState()changed.- See Also:
- Constant Field Values
-
EVENT_PLAY_WHEN_READY_CHANGED
static final int EVENT_PLAY_WHEN_READY_CHANGED
getPlayWhenReady()changed.- See Also:
- Constant Field Values
-
EVENT_PLAYBACK_SUPPRESSION_REASON_CHANGED
static final int EVENT_PLAYBACK_SUPPRESSION_REASON_CHANGED
getPlaybackSuppressionReason()changed.- See Also:
- Constant Field Values
-
EVENT_IS_PLAYING_CHANGED
static final int EVENT_IS_PLAYING_CHANGED
isPlaying()changed.- See Also:
- Constant Field Values
-
EVENT_REPEAT_MODE_CHANGED
static final int EVENT_REPEAT_MODE_CHANGED
getRepeatMode()changed.- See Also:
- Constant Field Values
-
EVENT_SHUFFLE_MODE_ENABLED_CHANGED
static final int EVENT_SHUFFLE_MODE_ENABLED_CHANGED
getShuffleModeEnabled()changed.- See Also:
- Constant Field Values
-
EVENT_PLAYER_ERROR
static final int EVENT_PLAYER_ERROR
getPlayerError()changed.- See Also:
- Constant Field Values
-
EVENT_POSITION_DISCONTINUITY
static final int EVENT_POSITION_DISCONTINUITY
A position discontinuity occurred. SeePlayer.Listener.onPositionDiscontinuity(PositionInfo, PositionInfo, int).- See Also:
- Constant Field Values
-
EVENT_PLAYBACK_PARAMETERS_CHANGED
static final int EVENT_PLAYBACK_PARAMETERS_CHANGED
getPlaybackParameters()changed.- See Also:
- Constant Field Values
-
EVENT_AVAILABLE_COMMANDS_CHANGED
static final int EVENT_AVAILABLE_COMMANDS_CHANGED
isCommandAvailable(int)changed for at least onePlayer.Command.- See Also:
- Constant Field Values
-
EVENT_MEDIA_METADATA_CHANGED
static final int EVENT_MEDIA_METADATA_CHANGED
getMediaMetadata()changed.- See Also:
- Constant Field Values
-
EVENT_PLAYLIST_METADATA_CHANGED
static final int EVENT_PLAYLIST_METADATA_CHANGED
getPlaylistMetadata()changed.- See Also:
- Constant Field Values
-
EVENT_SEEK_BACK_INCREMENT_CHANGED
static final int EVENT_SEEK_BACK_INCREMENT_CHANGED
getSeekBackIncrement()changed.- See Also:
- Constant Field Values
-
EVENT_SEEK_FORWARD_INCREMENT_CHANGED
static final int EVENT_SEEK_FORWARD_INCREMENT_CHANGED
getSeekForwardIncrement()changed.- See Also:
- Constant Field Values
-
EVENT_MAX_SEEK_TO_PREVIOUS_POSITION_CHANGED
static final int EVENT_MAX_SEEK_TO_PREVIOUS_POSITION_CHANGED
getMaxSeekToPreviousPosition()changed.- See Also:
- Constant Field Values
-
EVENT_TRACK_SELECTION_PARAMETERS_CHANGED
static final int EVENT_TRACK_SELECTION_PARAMETERS_CHANGED
getTrackSelectionParameters()changed.- See Also:
- Constant Field Values
-
COMMAND_PLAY_PAUSE
static final int COMMAND_PLAY_PAUSE
Command to start, pause or resume playback.- See Also:
- Constant Field Values
-
COMMAND_PREPARE
static final int COMMAND_PREPARE
Command to prepare the player.- See Also:
- Constant Field Values
-
COMMAND_STOP
static final int COMMAND_STOP
Command to stop playback or release the player.- See Also:
- Constant Field Values
-
COMMAND_SEEK_TO_DEFAULT_POSITION
static final int COMMAND_SEEK_TO_DEFAULT_POSITION
Command to seek to the default position of the currentMediaItem.- See Also:
- Constant Field Values
-
COMMAND_SEEK_IN_CURRENT_MEDIA_ITEM
static final int COMMAND_SEEK_IN_CURRENT_MEDIA_ITEM
Command to seek anywhere into the currentMediaItem.- See Also:
- Constant Field Values
-
COMMAND_SEEK_IN_CURRENT_WINDOW
@Deprecated static final int COMMAND_SEEK_IN_CURRENT_WINDOW
Deprecated.UseCOMMAND_SEEK_IN_CURRENT_MEDIA_ITEMinstead.- See Also:
- Constant Field Values
-
COMMAND_SEEK_TO_PREVIOUS_MEDIA_ITEM
static final int COMMAND_SEEK_TO_PREVIOUS_MEDIA_ITEM
Command to seek to the default position of the previousMediaItem.- See Also:
- Constant Field Values
-
COMMAND_SEEK_TO_PREVIOUS_WINDOW
@Deprecated static final int COMMAND_SEEK_TO_PREVIOUS_WINDOW
Deprecated.UseCOMMAND_SEEK_TO_PREVIOUS_MEDIA_ITEMinstead.- See Also:
- Constant Field Values
-
COMMAND_SEEK_TO_PREVIOUS
static final int COMMAND_SEEK_TO_PREVIOUS
Command to seek to an earlier position in the current or previousMediaItem.- See Also:
- Constant Field Values
-
COMMAND_SEEK_TO_NEXT_MEDIA_ITEM
static final int COMMAND_SEEK_TO_NEXT_MEDIA_ITEM
Command to seek to the default position of the nextMediaItem.- See Also:
- Constant Field Values
-
COMMAND_SEEK_TO_NEXT_WINDOW
@Deprecated static final int COMMAND_SEEK_TO_NEXT_WINDOW
Deprecated.UseCOMMAND_SEEK_TO_NEXT_MEDIA_ITEMinstead.- See Also:
- Constant Field Values
-
COMMAND_SEEK_TO_NEXT
static final int COMMAND_SEEK_TO_NEXT
Command to seek to a later position in the current or nextMediaItem.- See Also:
- Constant Field Values
-
COMMAND_SEEK_TO_MEDIA_ITEM
static final int COMMAND_SEEK_TO_MEDIA_ITEM
Command to seek anywhere in anyMediaItem.- See Also:
- Constant Field Values
-
COMMAND_SEEK_TO_WINDOW
@Deprecated static final int COMMAND_SEEK_TO_WINDOW
Deprecated.UseCOMMAND_SEEK_TO_MEDIA_ITEMinstead.- See Also:
- Constant Field Values
-
COMMAND_SEEK_BACK
static final int COMMAND_SEEK_BACK
Command to seek back by a fixed increment into the currentMediaItem.- See Also:
- Constant Field Values
-
COMMAND_SEEK_FORWARD
static final int COMMAND_SEEK_FORWARD
Command to seek forward by a fixed increment into the currentMediaItem.- See Also:
- Constant Field Values
-
COMMAND_SET_SPEED_AND_PITCH
static final int COMMAND_SET_SPEED_AND_PITCH
Command to set the playback speed and pitch.- See Also:
- Constant Field Values
-
COMMAND_SET_SHUFFLE_MODE
static final int COMMAND_SET_SHUFFLE_MODE
Command to enable shuffling.- See Also:
- Constant Field Values
-
COMMAND_SET_REPEAT_MODE
static final int COMMAND_SET_REPEAT_MODE
Command to set the repeat mode.- See Also:
- Constant Field Values
-
COMMAND_GET_CURRENT_MEDIA_ITEM
static final int COMMAND_GET_CURRENT_MEDIA_ITEM
Command to get the currently playingMediaItem.- See Also:
- Constant Field Values
-
COMMAND_GET_TIMELINE
static final int COMMAND_GET_TIMELINE
Command to get the information about the current timeline.- See Also:
- Constant Field Values
-
COMMAND_GET_MEDIA_ITEMS_METADATA
static final int COMMAND_GET_MEDIA_ITEMS_METADATA
Command to get theMediaItemsmetadata.- See Also:
- Constant Field Values
-
COMMAND_SET_MEDIA_ITEMS_METADATA
static final int COMMAND_SET_MEDIA_ITEMS_METADATA
Command to set theMediaItemsmetadata.- See Also:
- Constant Field Values
-
COMMAND_CHANGE_MEDIA_ITEMS
static final int COMMAND_CHANGE_MEDIA_ITEMS
Command to change theMediaItemsin the playlist.- See Also:
- Constant Field Values
-
COMMAND_GET_AUDIO_ATTRIBUTES
static final int COMMAND_GET_AUDIO_ATTRIBUTES
Command to get the player currentAudioAttributes.- See Also:
- Constant Field Values
-
COMMAND_GET_VOLUME
static final int COMMAND_GET_VOLUME
Command to get the player volume.- See Also:
- Constant Field Values
-
COMMAND_GET_DEVICE_VOLUME
static final int COMMAND_GET_DEVICE_VOLUME
Command to get the device volume and whether it is muted.- See Also:
- Constant Field Values
-
COMMAND_SET_VOLUME
static final int COMMAND_SET_VOLUME
Command to set the player volume.- See Also:
- Constant Field Values
-
COMMAND_SET_DEVICE_VOLUME
static final int COMMAND_SET_DEVICE_VOLUME
Command to set the device volume and mute it.- See Also:
- Constant Field Values
-
COMMAND_ADJUST_DEVICE_VOLUME
static final int COMMAND_ADJUST_DEVICE_VOLUME
Command to increase and decrease the device volume and mute it.- See Also:
- Constant Field Values
-
COMMAND_SET_VIDEO_SURFACE
static final int COMMAND_SET_VIDEO_SURFACE
Command to set and clear the surface on which to render the video.- See Also:
- Constant Field Values
-
COMMAND_GET_TEXT
static final int COMMAND_GET_TEXT
Command to get the text that should currently be displayed by the player.- See Also:
- Constant Field Values
-
COMMAND_SET_TRACK_SELECTION_PARAMETERS
static final int COMMAND_SET_TRACK_SELECTION_PARAMETERS
Command to set the player's track selection parameters.- See Also:
- Constant Field Values
-
COMMAND_GET_TRACK_INFOS
static final int COMMAND_GET_TRACK_INFOS
Command to get track infos.- See Also:
- Constant Field Values
-
COMMAND_INVALID
static final int COMMAND_INVALID
Represents an invalidPlayer.Command.- See Also:
- Constant Field Values
-
-
Method Detail
-
getApplicationLooper
Looper getApplicationLooper()
Returns theLooperassociated with the application thread that's used to access the player and on which player events are received.
-
addListener
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().- Parameters:
listener- The listener to register.
-
removeListener
void removeListener(Player.Listener listener)
Unregister a listener registered throughaddListener(Listener). The listener will no longer receive events.- Parameters:
listener- The listener to unregister.
-
setMediaItems
void setMediaItems(List<MediaItem> mediaItems)
Clears the playlist, adds the specifiedMediaItemsand resets the position to the default position.- Parameters:
mediaItems- The newMediaItems.
-
setMediaItems
void setMediaItems(List<MediaItem> mediaItems, boolean resetPosition)
Clears the playlist and adds the specifiedMediaItems.- Parameters:
mediaItems- The newMediaItems.resetPosition- Whether the playback position should be reset to the default position in the firstTimeline.Window. If false, playback will start from the position defined bygetCurrentMediaItemIndex()andgetCurrentPosition().
-
setMediaItems
void setMediaItems(List<MediaItem> mediaItems, int startIndex, long startPositionMs)
Clears the playlist and adds the specifiedMediaItems.- Parameters:
mediaItems- The newMediaItems.startIndex- TheMediaItemindex to start playback from. IfC.INDEX_UNSETis passed, the current position is not reset.startPositionMs- The position in milliseconds to start playback from. IfC.TIME_UNSETis passed, the default position of the givenMediaItemis used. In any case, ifstartIndexis set toC.INDEX_UNSET, this parameter is ignored and the position is not reset at all.- Throws:
IllegalSeekPositionException- If the providedstartIndexis not within the bounds of the list of media items.
-
setMediaItem
void setMediaItem(MediaItem mediaItem)
Clears the playlist, adds the specifiedMediaItemand resets the position to the default position.- Parameters:
mediaItem- The newMediaItem.
-
setMediaItem
void setMediaItem(MediaItem mediaItem, long startPositionMs)
Clears the playlist and adds the specifiedMediaItem.- Parameters:
mediaItem- The newMediaItem.startPositionMs- The position in milliseconds to start playback from.
-
setMediaItem
void setMediaItem(MediaItem mediaItem, boolean resetPosition)
Clears the playlist and adds the specifiedMediaItem.- Parameters:
mediaItem- The newMediaItem.resetPosition- Whether the playback position should be reset to the default position. If false, playback will start from the position defined bygetCurrentMediaItemIndex()andgetCurrentPosition().
-
addMediaItem
void addMediaItem(MediaItem mediaItem)
Adds a media item to the end of the playlist.- Parameters:
mediaItem- TheMediaItemto add.
-
addMediaItem
void addMediaItem(int index, MediaItem mediaItem)Adds a media item at the given index of the playlist.- Parameters:
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- TheMediaItemto add.
-
addMediaItems
void addMediaItems(List<MediaItem> mediaItems)
Adds a list of media items to the end of the playlist.- Parameters:
mediaItems- TheMediaItemsto add.
-
addMediaItems
void addMediaItems(int index, List<MediaItem> mediaItems)Adds a list of media items at the given index of the playlist.- Parameters:
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.mediaItems- TheMediaItemsto add.
-
moveMediaItem
void moveMediaItem(int currentIndex, int newIndex)Moves the media item at the current index to the new index.- Parameters:
currentIndex- The current index of the media item to move.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
void moveMediaItems(int fromIndex, int toIndex, int newIndex)Moves the media item range to the new index.- Parameters:
fromIndex- The start of the range to move.toIndex- The first item not to be included in the range (exclusive).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.
-
removeMediaItem
void removeMediaItem(int index)
Removes the media item at the given index of the playlist.- Parameters:
index- The index at which to remove the media item.
-
removeMediaItems
void removeMediaItems(int fromIndex, int toIndex)Removes a range of media items from the playlist.- Parameters:
fromIndex- The index at which to start removing media items.toIndex- The index of the first item to be kept (exclusive). If the index is larger than the size of the playlist, media items to the end of the playlist are removed.
-
clearMediaItems
void clearMediaItems()
Clears the playlist.
-
isCommandAvailable
boolean isCommandAvailable(@Command @com.google.android.exoplayer2.Player.Command int command)
Returns whether the providedPlayer.Commandis available.This method does not execute the command.
Executing a command that is not available (for example, calling
seekToNextMediaItem()ifCOMMAND_SEEK_TO_NEXT_MEDIA_ITEMis unavailable) will neither throw an exception nor generate agetPlayerError()player error}.COMMAND_SEEK_TO_PREVIOUS_MEDIA_ITEMandCOMMAND_SEEK_TO_NEXT_MEDIA_ITEMare unavailable if there is no suchMediaItem.- Parameters:
command- APlayer.Command.- Returns:
- Whether the
Player.Commandis available. - See Also:
Player.Listener.onAvailableCommandsChanged(Commands)
-
canAdvertiseSession
boolean canAdvertiseSession()
Returns whether the player can be used to advertise a media session.
-
getAvailableCommands
Player.Commands getAvailableCommands()
Returns the player's currently availablePlayer.Commands.The returned
Player.Commandsare not updated when available commands change. UsePlayer.Listener.onAvailableCommandsChanged(Commands)to get an update when the available commands change.Executing a command that is not available (for example, calling
seekToNextMediaItem()ifCOMMAND_SEEK_TO_NEXT_MEDIA_ITEMis unavailable) will neither throw an exception nor generate agetPlayerError()player error}.COMMAND_SEEK_TO_PREVIOUS_MEDIA_ITEMandCOMMAND_SEEK_TO_NEXT_MEDIA_ITEMare unavailable if there is no suchMediaItem.- Returns:
- The currently available
Player.Commands. - See Also:
Player.Listener.onAvailableCommandsChanged(com.google.android.exoplayer2.Player.Commands)
-
prepare
void prepare()
Prepares the player.This will move the player out of
idle stateand the player will start loading media and acquire resources needed for playback.
-
getPlaybackState
@State @com.google.android.exoplayer2.Player.State int getPlaybackState()
Returns the currentplayback stateof the player.- Returns:
- The current
playback state. - See Also:
Player.Listener.onPlaybackStateChanged(int)
-
getPlaybackSuppressionReason
@PlaybackSuppressionReason @com.google.android.exoplayer2.Player.PlaybackSuppressionReason int getPlaybackSuppressionReason()
Returns the reason why playback is suppressed even thoughgetPlayWhenReady()istrue, orPLAYBACK_SUPPRESSION_REASON_NONEif playback is not suppressed.- Returns:
- The current
playback suppression reason. - See Also:
Player.Listener.onPlaybackSuppressionReasonChanged(int)
-
isPlaying
boolean isPlaying()
Returns whether the player is playing, i.e.getCurrentPosition()is advancing.If
false, then at least one of the following is true:- The
playback stateis notready. - There is no
intention to play. - Playback is
suppressed for other reasons.
- Returns:
- Whether the player is playing.
- See Also:
Player.Listener.onIsPlayingChanged(boolean)
- The
-
getPlayerError
@Nullable PlaybackException getPlayerError()
Returns the error that caused playback to fail. This is the same error that will have been reported viaPlayer.Listener.onPlayerError(PlaybackException)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
nullifgetPlaybackState()is notSTATE_IDLE.- Returns:
- The error, or
null. - See Also:
Player.Listener.onPlayerError(PlaybackException)
-
play
void play()
Resumes playback as soon asgetPlaybackState()==STATE_READY. Equivalent tosetPlayWhenReady(true).
-
pause
void pause()
Pauses playback. Equivalent tosetPlayWhenReady(false).
-
setPlayWhenReady
void setPlayWhenReady(boolean playWhenReady)
Sets whether playback should proceed whengetPlaybackState()==STATE_READY.If the player is already in the ready state then this method pauses and resumes playback.
- Parameters:
playWhenReady- Whether playback should proceed when ready.
-
getPlayWhenReady
boolean getPlayWhenReady()
Whether playback will proceed whengetPlaybackState()==STATE_READY.- Returns:
- Whether playback will proceed when ready.
- See Also:
Player.Listener.onPlayWhenReadyChanged(boolean, int)
-
setRepeatMode
void setRepeatMode(@RepeatMode @com.google.android.exoplayer2.Player.RepeatMode int repeatMode)
Sets thePlayer.RepeatModeto be used for playback.- Parameters:
repeatMode- The repeat mode.
-
getRepeatMode
@RepeatMode @com.google.android.exoplayer2.Player.RepeatMode int getRepeatMode()
Returns the currentPlayer.RepeatModeused for playback.- Returns:
- The current repeat mode.
- See Also:
Player.Listener.onRepeatModeChanged(int)
-
setShuffleModeEnabled
void setShuffleModeEnabled(boolean shuffleModeEnabled)
Sets whether shuffling of media items is enabled.- Parameters:
shuffleModeEnabled- Whether shuffling is enabled.
-
getShuffleModeEnabled
boolean getShuffleModeEnabled()
Returns whether shuffling of media items is enabled.
-
isLoading
boolean isLoading()
Whether the player is currently loading the source.- Returns:
- Whether the player is currently loading the source.
- See Also:
Player.Listener.onIsLoadingChanged(boolean)
-
seekToDefaultPosition
void seekToDefaultPosition()
Seeks to the default position associated with the currentMediaItem. 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.
-
seekToDefaultPosition
void seekToDefaultPosition(int mediaItemIndex)
Seeks to the default position associated with the specifiedMediaItem. 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.- Parameters:
mediaItemIndex- The index of theMediaItemwhose associated default position should be seeked to.- Throws:
IllegalSeekPositionException- If the player has a non-empty timeline and the providedmediaItemIndexis not within the bounds of the current timeline.
-
seekTo
void seekTo(long positionMs)
Seeks to a position specified in milliseconds in the currentMediaItem.- Parameters:
positionMs- The seek position in the currentMediaItem, orC.TIME_UNSETto seek to the media item's default position.
-
seekTo
void seekTo(int mediaItemIndex, long positionMs)Seeks to a position specified in milliseconds in the specifiedMediaItem.- Parameters:
mediaItemIndex- The index of theMediaItem.positionMs- The seek position in the specifiedMediaItem, orC.TIME_UNSETto seek to the media item's default position.- Throws:
IllegalSeekPositionException- If the player has a non-empty timeline and the providedmediaItemIndexis not within the bounds of the current timeline.
-
getSeekBackIncrement
long getSeekBackIncrement()
Returns theseekBack()increment.- Returns:
- The seek back increment, in milliseconds.
- See Also:
Player.Listener.onSeekBackIncrementChanged(long)
-
seekBack
void seekBack()
Seeks back in the currentMediaItembygetSeekBackIncrement()milliseconds.
-
getSeekForwardIncrement
long getSeekForwardIncrement()
Returns theseekForward()increment.- Returns:
- The seek forward increment, in milliseconds.
- See Also:
Player.Listener.onSeekForwardIncrementChanged(long)
-
seekForward
void seekForward()
Seeks forward in the currentMediaItembygetSeekForwardIncrement()milliseconds.
-
hasPrevious
@Deprecated boolean hasPrevious()
Deprecated.UsehasPreviousMediaItem()instead.
-
hasPreviousWindow
@Deprecated boolean hasPreviousWindow()
Deprecated.UsehasPreviousMediaItem()instead.
-
hasPreviousMediaItem
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 isREPEAT_MODE_OFF. SeeREPEAT_MODE_ONEfor more details.
-
previous
@Deprecated void previous()
Deprecated.UseseekToPreviousMediaItem()instead.
-
seekToPreviousWindow
@Deprecated void seekToPreviousWindow()
Deprecated.UseseekToPreviousMediaItem()instead.
-
seekToPreviousMediaItem
void seekToPreviousMediaItem()
Seeks to the default position of the previousMediaItem, which may depend on the current repeat mode and whether shuffle mode is enabled. Does nothing ifhasPreviousMediaItem()isfalse.Note: When the repeat mode is
REPEAT_MODE_ONE, this method behaves the same as when the current repeat mode isREPEAT_MODE_OFF. SeeREPEAT_MODE_ONEfor more details.
-
getMaxSeekToPreviousPosition
long getMaxSeekToPreviousPosition()
Returns the maximum position for whichseekToPrevious()seeks to the previousMediaItem, in milliseconds.- Returns:
- The maximum seek to previous position, in milliseconds.
- See Also:
Player.EventListener.onMaxSeekToPreviousPositionChanged(long)
-
seekToPrevious
void seekToPrevious()
Seeks to an earlier position in the current or previousMediaItem(if available). More precisely:- If the timeline is empty or seeking is not possible, does nothing.
- Otherwise, if the current
MediaItemisisCurrentMediaItemLive()live} andunseekable, then:- If
a previous media item exists, seeks to the default position of the previous media item. - Otherwise, does nothing.
- If
- Otherwise, if
a previous media item existsand thecurrent positionis less thangetMaxSeekToPreviousPosition(), seeks to the default position of the previousMediaItem. - Otherwise, seeks to 0 in the current
MediaItem.
-
hasNext
@Deprecated boolean hasNext()
Deprecated.UsehasNextMediaItem()instead.
-
hasNextWindow
@Deprecated boolean hasNextWindow()
Deprecated.UsehasNextMediaItem()instead.
-
hasNextMediaItem
boolean hasNextMediaItem()
Returns whether a nextMediaItemexists, 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 isREPEAT_MODE_OFF. SeeREPEAT_MODE_ONEfor more details.
-
next
@Deprecated void next()
Deprecated.UseseekToNextMediaItem()instead.
-
seekToNextWindow
@Deprecated void seekToNextWindow()
Deprecated.UseseekToNextMediaItem()instead.
-
seekToNextMediaItem
void seekToNextMediaItem()
Seeks to the default position of the nextMediaItem, which may depend on the current repeat mode and whether shuffle mode is enabled. Does nothing ifhasNextMediaItem()isfalse.Note: When the repeat mode is
REPEAT_MODE_ONE, this method behaves the same as when the current repeat mode isREPEAT_MODE_OFF. SeeREPEAT_MODE_ONEfor more details.
-
seekToNext
void seekToNext()
Seeks to a later position in the current or nextMediaItem(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 nextMediaItem. - Otherwise, if the current
MediaItemisliveand has not ended, seeks to the live edge of the currentMediaItem. - Otherwise, does nothing.
-
setPlaybackParameters
void setPlaybackParameters(PlaybackParameters playbackParameters)
Attempts to set the playback parameters. PassingPlaybackParameters.DEFAULTresets the player to the default, which means there is no speed or pitch adjustment.Playback parameters changes may cause the player to buffer.
Player.Listener.onPlaybackParametersChanged(PlaybackParameters)will be called whenever the currently active playback parameters change.- Parameters:
playbackParameters- The playback parameters.
-
setPlaybackSpeed
void setPlaybackSpeed(@FloatRange(from=0.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)).- Parameters:
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...
-
getPlaybackParameters
PlaybackParameters getPlaybackParameters()
Returns the currently active playback parameters.
-
stop
void stop()
Stops playback without resetting the playlist. Usepause()rather than this method if the intention is to pause playback.Calling this method will cause the playback state to transition to
STATE_IDLEand the player will release the loaded media and resources required for playback. The player instance can still be used by callingprepare()again, andrelease()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.
-
stop
@Deprecated void stop(boolean reset)
Deprecated.Usestop()andclearMediaItems()(ifresetis true) or juststop()(ifresetis false). Any player error will be cleared whenre-preparingthe player.
-
release
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.
-
getCurrentTrackGroups
@Deprecated TrackGroupArray getCurrentTrackGroups()
Deprecated.Returns the available track groups.
-
getCurrentTrackSelections
@Deprecated TrackSelectionArray getCurrentTrackSelections()
Deprecated.Returns the current track selections.A concrete implementation may include null elements if it has a fixed number of renderer components, wishes to report a TrackSelection for each of them, and has one or more renderer components that is not assigned any selected tracks.
-
getCurrentTracksInfo
TracksInfo getCurrentTracksInfo()
Returns the available tracks, as well as the tracks' support, type, and selection status.
-
getTrackSelectionParameters
TrackSelectionParameters getTrackSelectionParameters()
Returns the parameters constraining the track selection.- See Also:
}
-
setTrackSelectionParameters
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())
-
getMediaMetadata
MediaMetadata getMediaMetadata()
Returns the current combinedMediaMetadata, orMediaMetadata.EMPTYif not supported.This
MediaMetadatais a combination of theMediaItem.mediaMetadataand the static and dynamic metadata from thetrack selections' formatsandPlayer.Listener.onMetadata(Metadata). If a field is populated in theMediaItem.mediaMetadata, it will be prioritised above the same field coming from static or dynamic metadata.
-
getPlaylistMetadata
MediaMetadata getPlaylistMetadata()
Returns the playlistMediaMetadata, as set bysetPlaylistMetadata(MediaMetadata), orMediaMetadata.EMPTYif not supported.
-
setPlaylistMetadata
void setPlaylistMetadata(MediaMetadata mediaMetadata)
Sets the playlistMediaMetadata.
-
getCurrentManifest
@Nullable Object getCurrentManifest()
Returns the current manifest. The type depends on the type of media being played. May be null.
-
getCurrentTimeline
Timeline getCurrentTimeline()
Returns the currentTimeline. Never null, but may be empty.
-
getCurrentPeriodIndex
int getCurrentPeriodIndex()
Returns the index of the period currently being played.
-
getCurrentWindowIndex
@Deprecated int getCurrentWindowIndex()
Deprecated.UsegetCurrentMediaItemIndex()instead.
-
getCurrentMediaItemIndex
int getCurrentMediaItemIndex()
Returns the index of the currentMediaItemin thetimeline, or the prospective index if thecurrent timelineis empty.
-
getNextWindowIndex
@Deprecated int getNextWindowIndex()
Deprecated.UsegetNextMediaItemIndex()instead.
-
getNextMediaItemIndex
int getNextMediaItemIndex()
Returns the index of theMediaItemthat will be played ifseekToNextMediaItem()is called, which may depend on the current repeat mode and whether shuffle mode is enabled. ReturnsC.INDEX_UNSETifhasNextMediaItem()isfalse.Note: When the repeat mode is
REPEAT_MODE_ONE, this method behaves the same as when the current repeat mode isREPEAT_MODE_OFF. SeeREPEAT_MODE_ONEfor more details.
-
getPreviousWindowIndex
@Deprecated int getPreviousWindowIndex()
Deprecated.UsegetPreviousMediaItemIndex()instead.
-
getPreviousMediaItemIndex
int getPreviousMediaItemIndex()
Returns the index of theMediaItemthat will be played ifseekToPreviousMediaItem()is called, which may depend on the current repeat mode and whether shuffle mode is enabled. ReturnsC.INDEX_UNSETifhasPreviousMediaItem()isfalse.Note: When the repeat mode is
REPEAT_MODE_ONE, this method behaves the same as when the current repeat mode isREPEAT_MODE_OFF. SeeREPEAT_MODE_ONEfor more details.
-
getCurrentMediaItem
@Nullable MediaItem getCurrentMediaItem()
Returns the currently playingMediaItem. May be null if the timeline is empty.
-
getMediaItemCount
int getMediaItemCount()
Returns the number ofmedia itemsin the playlist.
-
getDuration
long getDuration()
Returns the duration of the current content or ad in milliseconds, orC.TIME_UNSETif the duration is not known.
-
getCurrentPosition
long getCurrentPosition()
Returns the playback position in the current content or ad, in milliseconds, or the prospective position in milliseconds if thecurrent timelineis empty.
-
getBufferedPosition
long getBufferedPosition()
Returns an estimate of the position in the current content or ad up to which data is buffered, in milliseconds.
-
getBufferedPercentage
@IntRange(from=0L, to=100L) 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.
-
getTotalBufferedDuration
long getTotalBufferedDuration()
Returns an estimate of the total buffered duration from the current position, in milliseconds. This includes pre-buffered data for subsequent ads andmedia items.
-
isCurrentWindowDynamic
@Deprecated boolean isCurrentWindowDynamic()
Deprecated.UseisCurrentMediaItemDynamic()instead.
-
isCurrentMediaItemDynamic
boolean isCurrentMediaItemDynamic()
Returns whether the currentMediaItemis dynamic (may change when theTimelineis updated), orfalseif theTimelineis empty.- See Also:
Timeline.Window.isDynamic
-
isCurrentWindowLive
@Deprecated boolean isCurrentWindowLive()
Deprecated.UseisCurrentMediaItemLive()instead.
-
isCurrentMediaItemLive
boolean isCurrentMediaItemLive()
- See Also:
Timeline.Window.isLive()
-
getCurrentLiveOffset
long getCurrentLiveOffset()
Returns the offset of the current playback position from the live edge in milliseconds, orC.TIME_UNSETif the currentMediaItemisCurrentMediaItemLive()isn'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.
-
isCurrentWindowSeekable
@Deprecated boolean isCurrentWindowSeekable()
Deprecated.UseisCurrentMediaItemSeekable()instead.
-
isCurrentMediaItemSeekable
boolean isCurrentMediaItemSeekable()
- See Also:
Timeline.Window.isSeekable
-
isPlayingAd
boolean isPlayingAd()
Returns whether the player is currently playing an ad.
-
getCurrentAdGroupIndex
int getCurrentAdGroupIndex()
IfisPlayingAd()returns true, returns the index of the ad group in the period currently being played. ReturnsC.INDEX_UNSETotherwise.
-
getCurrentAdIndexInAdGroup
int getCurrentAdIndexInAdGroup()
IfisPlayingAd()returns true, returns the index of the ad in its ad group. ReturnsC.INDEX_UNSETotherwise.
-
getContentDuration
long getContentDuration()
IfisPlayingAd()returnstrue, returns the duration of the current content in milliseconds, orC.TIME_UNSETif the duration is not known. If there is no ad playing, the returned duration is the same as that returned bygetDuration().
-
getContentPosition
long getContentPosition()
IfisPlayingAd()returnstrue, 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 bygetCurrentPosition().
-
getContentBufferedPosition
long getContentBufferedPosition()
IfisPlayingAd()returnstrue, 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 bygetBufferedPosition().
-
getAudioAttributes
AudioAttributes getAudioAttributes()
Returns the attributes for audio playback.
-
setVolume
void setVolume(@FloatRange(from=0.0,to=1.0) float volume)Sets the audio volume, valid values are between 0 (silence) and 1 (unity gain, signal unchanged), inclusive.- Parameters:
volume- Linear output gain to apply to all audio channels.
-
getVolume
@FloatRange(from=0.0, to=1.0) float getVolume()Returns the audio volume, with 0 being silence and 1 being unity gain (signal unchanged).- Returns:
- The linear gain applied to all audio channels.
-
clearVideoSurface
void clearVideoSurface()
-
clearVideoSurface
void clearVideoSurface(@Nullable Surface surface)Clears theSurfaceonto which video is being rendered if it matches the one passed. Else does nothing.- Parameters:
surface- The surface to clear.
-
setVideoSurface
void setVideoSurface(@Nullable Surface surface)Sets theSurfaceonto which video will be rendered. The caller is responsible for tracking the lifecycle of the surface, and must clear the surface by callingsetVideoSurface(null)if the surface is destroyed.If the surface is held by a
SurfaceView,TextureVieworSurfaceHolderthen it's recommended to usesetVideoSurfaceView(SurfaceView),setVideoTextureView(TextureView)orsetVideoSurfaceHolder(SurfaceHolder)rather than this method, since passing the holder allows the player to track the lifecycle of the surface automatically.- Parameters:
surface- TheSurface.
-
setVideoSurfaceHolder
void setVideoSurfaceHolder(@Nullable SurfaceHolder surfaceHolder)Sets theSurfaceHolderthat holds theSurfaceonto which video will be rendered. The player will track the lifecycle of the surface automatically.The thread that calls the
SurfaceHolder.Callbackmethods must be the thread associated withgetApplicationLooper().- Parameters:
surfaceHolder- The surface holder.
-
clearVideoSurfaceHolder
void clearVideoSurfaceHolder(@Nullable SurfaceHolder surfaceHolder)Clears theSurfaceHolderthat holds theSurfaceonto which video is being rendered if it matches the one passed. Else does nothing.- Parameters:
surfaceHolder- The surface holder to clear.
-
setVideoSurfaceView
void setVideoSurfaceView(@Nullable SurfaceView surfaceView)Sets theSurfaceViewonto which video will be rendered. The player will track the lifecycle of the surface automatically.The thread that calls the
SurfaceHolder.Callbackmethods must be the thread associated withgetApplicationLooper().- Parameters:
surfaceView- The surface view.
-
clearVideoSurfaceView
void clearVideoSurfaceView(@Nullable SurfaceView surfaceView)Clears theSurfaceViewonto which video is being rendered if it matches the one passed. Else does nothing.- Parameters:
surfaceView- The texture view to clear.
-
setVideoTextureView
void setVideoTextureView(@Nullable TextureView textureView)Sets theTextureViewonto which video will be rendered. The player will track the lifecycle of the surface automatically.The thread that calls the
TextureView.SurfaceTextureListenermethods must be the thread associated withgetApplicationLooper().- Parameters:
textureView- The texture view.
-
clearVideoTextureView
void clearVideoTextureView(@Nullable TextureView textureView)Clears theTextureViewonto which video is being rendered if it matches the one passed. Else does nothing.- Parameters:
textureView- The texture view to clear.
-
getVideoSize
VideoSize getVideoSize()
Gets the size of the video.The video's width and height are
0if there is no video or its size has not been determined yet.
-
getDeviceInfo
DeviceInfo getDeviceInfo()
Gets the device information.
-
getDeviceVolume
@IntRange(from=0L) int getDeviceVolume()
Gets the current volume of the device.For devices with
local playback, the volume returned by this method varies according to the currentstream type. The stream type is determined byAudioAttributes.usagewhich can be converted to stream type withUtil.getStreamTypeForAudioUsage(int).For devices with
remote playback, the volume of the remote device is returned.
-
isDeviceMuted
boolean isDeviceMuted()
Gets whether the device is muted or not.
-
setDeviceVolume
void setDeviceVolume(@IntRange(from=0L) int volume)Sets the volume of the device.- Parameters:
volume- The volume to set.
-
increaseDeviceVolume
void increaseDeviceVolume()
Increases the volume of the device.
-
decreaseDeviceVolume
void decreaseDeviceVolume()
Decreases the volume of the device.
-
setDeviceMuted
void setDeviceMuted(boolean muted)
Sets the mute state of the device.
-
-