ListenableFuture<SessionPlayer.PlayerResult!> |
addPlaylistItem(index: Int, @NonNull item: MediaItem)
Adds the media item to the playlist at the index. Index equals to or greater than the current playlist size (e.g. Integer#MAX_VALUE) will add the item at the end of the playlist.
If index is less than or equal to the current index of the playlist, the current index of the playlist should be increased correspondingly.
The implementation must notify registered callbacks with PlayerCallback#onPlaylistChanged(SessionPlayer, List, MediaMetadata) when it's completed.
The implementation must close the ParcelFileDescriptor in the FileMediaItem if the given media item is a FileMediaItem.
On success, a PlayerResult should be returned with item added.
|
Unit |
close()
Removes all existing references to callbacks and executors. Note: Sub classes of SessionPlayer that override this API should call this super method.
|
ListenableFuture<SessionPlayer.PlayerResult!> |
deselectTrack(@NonNull trackInfo: SessionPlayer.TrackInfo)
Deselects the TrackInfo for the current media item.
Generally, a track should already be selected in order to be deselected, and audio and video tracks should not be deselected.
The types of tracks supported may vary based on player implementation.
Note: getSelectedTrack(int) returns the currently selected track per track type that can be deselected, but the list may be invalidated when PlayerCallback#onTracksChanged(SessionPlayer, List) is called.
|
AudioAttributesCompat? |
getAudioAttributes()
Gets the AudioAttributesCompat that media player has.
|
Long |
getBufferedPosition()
Gets the position for how much has been buffered, or UNKNOWN_TIME if unknown.
The position is the relative position based on the MediaItem#getStartPosition(). So the position 0 means the start position of the MediaItem.
|
Int |
getBufferingState()
Returns the current buffering state of the player.
During the buffering, see getBufferedPosition() for the quantifying the amount already buffered.
|
MutableList<Pair<SessionPlayer.PlayerCallback!, Executor!>!> |
getCallbacks()
Gets the callbacks with executors for subclasses to notify player events.
|
MediaItem? |
getCurrentMediaItem()
Gets the current media item, which is currently playing or would be played with later play. This value may be updated when PlayerCallback#onCurrentMediaItemChanged(SessionPlayer, MediaItem) or PlayerCallback#onPlaylistChanged(SessionPlayer, List, MediaMetadata) is called.
|
Int |
getCurrentMediaItemIndex()
Gets the index of current media item in playlist. This value should be updated when PlayerCallback#onCurrentMediaItemChanged(SessionPlayer, MediaItem) or PlayerCallback#onPlaylistChanged(SessionPlayer, List, MediaMetadata) is called.
|
Long |
getCurrentPosition()
Gets the current playback position.
The position is the relative position based on the MediaItem#getStartPosition(). So the position 0 means the start position of the MediaItem.
|
Long |
getDuration()
Gets the duration of the current media item, or UNKNOWN_TIME if unknown. If the current MediaItem has either start or end position, then duration would be adjusted accordingly instead of returning the whole size of the MediaItem.
|
Int |
getNextMediaItemIndex()
Gets the next item index in the playlist. This value should be updated when PlayerCallback#onCurrentMediaItemChanged(SessionPlayer, MediaItem) or PlayerCallback#onPlaylistChanged(SessionPlayer, List, MediaMetadata) is called.
|
Float |
getPlaybackSpeed()
Gets the actual playback speed to be used by the player when playing. A value of 1.0f is the default playback value, and a negative value indicates reverse playback.
Note that it may differ from the speed set in setPlaybackSpeed(float).
|
Int |
getPlayerState()
Gets the current player state.
|
MutableList<MediaItem!>? |
getPlaylist()
Gets the playlist. It can be null if the playlist hasn't been set or it's reset by setMediaItem.
|
MediaMetadata? |
getPlaylistMetadata()
Gets the playlist metadata.
|
Int |
getPreviousMediaItemIndex()
Gets the previous item index in the playlist. This value should be updated when PlayerCallback#onCurrentMediaItemChanged(SessionPlayer, MediaItem) or PlayerCallback#onPlaylistChanged(SessionPlayer, List, MediaMetadata) is called.
|
Int |
getRepeatMode()
Gets the repeat mode.
|
SessionPlayer.TrackInfo? |
getSelectedTrack(trackType: Int)
Gets currently selected track's TrackInfo for the given track type.
The returned value can be outdated after PlayerCallback#onTracksChanged(SessionPlayer, List), PlayerCallback#onTrackSelected(SessionPlayer, TrackInfo), or PlayerCallback#onTrackDeselected(SessionPlayer, TrackInfo) is called.
|
Int |
getShuffleMode()
Gets the shuffle mode.
|
MutableList<SessionPlayer.TrackInfo!> |
getTracks()
Gets the full list of selected and unselected tracks that the media contains. The order of the list is irrelevant as different players expose tracks in different ways, but the tracks will generally be ordered based on track type.
The types of tracks supported may vary based on player implementation.
|
VideoSize |
getVideoSize()
Gets the size of the video.
|
ListenableFuture<SessionPlayer.PlayerResult!> |
movePlaylistItem(@IntRange(0) fromIndex: Int, @IntRange(0) toIndex: Int)
Moves the media item at fromIdx to toIdx in the playlist.
The implementation must notify registered callbacks with PlayerCallback#onPlaylistChanged(SessionPlayer, List, MediaMetadata) when it's completed.
On success, a PlayerResult should be returned with item set.
|
ListenableFuture<SessionPlayer.PlayerResult!> |
pause()
Pauses playback.
On success, this transfers the player state to PLAYER_STATE_PAUSED and a PlayerResult should be returned with the current media item when the command was completed. If it is called in PLAYER_STATE_IDLE or PLAYER_STATE_ERROR, it should be ignored and a PlayerResult should be returned with PlayerResult#RESULT_ERROR_INVALID_STATE.
|
ListenableFuture<SessionPlayer.PlayerResult!> |
play()
Starts or resumes playback.
On success, this transfers the player state to PLAYER_STATE_PLAYING and a PlayerResult should be returned with the current media item when the command was completed. If it is called in PLAYER_STATE_IDLE or PLAYER_STATE_ERROR, it should be ignored and a PlayerResult should be returned with PlayerResult#RESULT_ERROR_INVALID_STATE.
|
ListenableFuture<SessionPlayer.PlayerResult!> |
prepare()
Prepares the media items for playback. During this time, the player may allocate resources required to play, such as audio and video decoders. Before calling this API, set media item(s) through either setMediaItem or setPlaylist.
On success, this transfers the player state from PLAYER_STATE_IDLE to PLAYER_STATE_PAUSED and a PlayerResult should be returned with the prepared media item when the command completed. If it's not called in PLAYER_STATE_IDLE, it should be ignored and PlayerResult should be returned with PlayerResult#RESULT_ERROR_INVALID_STATE.
|
Unit |
registerPlayerCallback(@NonNull executor: Executor, @NonNull callback: SessionPlayer.PlayerCallback)
Register PlayerCallback to listen changes.
|
ListenableFuture<SessionPlayer.PlayerResult!> |
removePlaylistItem(@IntRange(0) index: Int)
Removes the media item from the playlist
The implementation must notify registered callbacks with PlayerCallback#onPlaylistChanged(SessionPlayer, List, MediaMetadata) when it's completed.
On success, a PlayerResult should be returned with item removed.
|
ListenableFuture<SessionPlayer.PlayerResult!> |
replacePlaylistItem(index: Int, @NonNull item: MediaItem)
Replaces the media item at index in the playlist. This can be also used to update metadata of an item.
The implementation must notify registered callbacks with PlayerCallback#onPlaylistChanged(SessionPlayer, List, MediaMetadata) when it's completed.
The implementation must close the ParcelFileDescriptor in the FileMediaItem if the given media item is a FileMediaItem.
On success, a PlayerResult should be returned with item set.
|
ListenableFuture<SessionPlayer.PlayerResult!> |
seekTo(position: Long)
Seeks to the specified position.
The position is the relative position based on the MediaItem#getStartPosition(). So calling seekTo(long) with 0 means the seek to the start position.
On success, a PlayerResult should be returned with the current media item when the command completed. If it's called in PLAYER_STATE_IDLE, it is ignored and a PlayerResult should be returned with PlayerResult#RESULT_ERROR_INVALID_STATE.
|
ListenableFuture<SessionPlayer.PlayerResult!> |
selectTrack(@NonNull trackInfo: SessionPlayer.TrackInfo)
Selects the TrackInfo for the current media item.
Generally one track will be selected for each track type.
The types of tracks supported may vary based on player implementation.
Note: getTracks() returns the list of tracks that can be selected, but the list may be invalidated when PlayerCallback#onTracksChanged(SessionPlayer, List) is called.
|
ListenableFuture<SessionPlayer.PlayerResult!> |
setAudioAttributes(@NonNull attributes: AudioAttributesCompat)
Sets the AudioAttributesCompat to be used during the playback of the media.
You must call this method in PLAYER_STATE_IDLE in order for the audio attributes to become effective thereafter. Otherwise, the call would be ignored and PlayerResult should be returned with PlayerResult#RESULT_ERROR_INVALID_STATE.
On success, a PlayerResult should be returned with the current media item when the command completed.
|
ListenableFuture<SessionPlayer.PlayerResult!> |
setMediaItem(@NonNull item: MediaItem)
Sets a MediaItem for playback. Use this or setPlaylist to specify which items to play. If you want to change current item in the playlist, use one of skipToPlaylistItem, skipToNextPlaylistItem, or skipToPreviousPlaylistItem instead of this method.
This can be called multiple times in any states other than PLAYER_STATE_ERROR. This would override previous setMediaItem or setPlaylist calls.
It's recommended to fill MediaMetadata in MediaItem especially for the duration information with the key MediaMetadata#METADATA_KEY_DURATION. Without the duration information in the metadata, session will do extra work to get the duration and send it to the controller.
The implementation must notify registered callbacks with PlayerCallback#onPlaylistChanged and PlayerCallback#onCurrentMediaItemChanged when it's completed. The current item would be the item given here.
The implementation must close the ParcelFileDescriptor in the FileMediaItem if the given media item is a FileMediaItem.
On success, a PlayerResult should be returned with item set.
|
ListenableFuture<SessionPlayer.PlayerResult!> |
setPlaybackSpeed(playbackSpeed: Float)
Sets the playback speed. The default playback speed is 1.0f, and negative values indicate reverse playback and 0.0f is not allowed.
The supported playback speed range depends on the underlying player implementation, so it is recommended to query the actual speed of the player via getPlaybackSpeed() after the operation completes. In particular, please note that player implementations may not support reverse playback.
On success, a PlayerResult should be returned with the current media item when the command completed.
|
ListenableFuture<SessionPlayer.PlayerResult!> |
setPlaylist(@NonNull list: MutableList<MediaItem!>, @Nullable metadata: MediaMetadata?)
Sets a list of MediaItem with metadata. Use this or setMediaItem to specify which items to play.
This can be called multiple times in any states other than PLAYER_STATE_ERROR. This would override previous setMediaItem or setPlaylist calls.
Ensure uniqueness of each MediaItem in the playlist so the session can uniquely identity individual items. All MediaItems shouldn't be null as well.
It's recommended to fill MediaMetadata in each MediaItem especially for the duration information with the key MediaMetadata#METADATA_KEY_DURATION. Without the duration information in the metadata, session will do extra work to get the duration and send it to the controller.
The implementation must notify registered callbacks with PlayerCallback#onPlaylistChanged and PlayerCallback#onCurrentMediaItemChanged when it's completed. The current media item would be the first item in the playlist.
The implementation must close the ParcelFileDescriptor in the FileMediaItem when a media item in the playlist is a FileMediaItem.
On success, a PlayerResult should be returned with the first media item of the playlist when the command completed.
|
ListenableFuture<SessionPlayer.PlayerResult!> |
setRepeatMode(repeatMode: Int)
Sets the repeat mode.
The implementation must notify registered callbacks with PlayerCallback#onRepeatModeChanged(SessionPlayer, int) when it's completed.
On success, a PlayerResult should be returned with the current media item when the command completed.
|
ListenableFuture<SessionPlayer.PlayerResult!> |
setShuffleMode(shuffleMode: Int)
Sets the shuffle mode.
The implementation must notify registered callbacks with PlayerCallback#onShuffleModeChanged(SessionPlayer, int) when it's completed.
On success, a PlayerResult should be returned with the current media item when the command completed.
|
ListenableFuture<SessionPlayer.PlayerResult!> |
setSurface(@Nullable surface: Surface?)
Sets the Surface to be used as the sink for the video portion of the media.
A null surface will reset any Surface and result in only the audio track being played.
On success, a SessionPlayer.PlayerResult is returned with the current media item when the command completed.
|
ListenableFuture<SessionPlayer.PlayerResult!> |
skipToNextPlaylistItem()
Skips to the next item in the playlist.
The implementation must notify registered callbacks with PlayerCallback#onCurrentMediaItemChanged(SessionPlayer, MediaItem) when it's completed.
On success, a PlayerResult should be returned with the current media item when the command completed.
|
ListenableFuture<SessionPlayer.PlayerResult!> |
skipToPlaylistItem(@IntRange(0) index: Int)
Skips to the item in the playlist at the index.
The implementation must notify registered callbacks with PlayerCallback#onCurrentMediaItemChanged(SessionPlayer, MediaItem) when it's completed.
On success, a PlayerResult should be returned with the current media item when the command completed.
|
ListenableFuture<SessionPlayer.PlayerResult!> |
skipToPreviousPlaylistItem()
Skips to the previous item in the playlist.
The implementation must notify registered callbacks with PlayerCallback#onCurrentMediaItemChanged(SessionPlayer, MediaItem) when it's completed.
On success, a PlayerResult should be returned with the current media item when the command completed.
|
Unit |
unregisterPlayerCallback(@NonNull callback: SessionPlayer.PlayerCallback)
Unregister the previously registered PlayerCallback.
|
ListenableFuture<SessionPlayer.PlayerResult!> |
updatePlaylistMetadata(@Nullable metadata: MediaMetadata?)
Updates the playlist metadata while keeping the playlist as-is.
The implementation must notify registered callbacks with PlayerCallback#onPlaylistMetadataChanged(SessionPlayer, MediaMetadata) when it's completed.
On success, a PlayerResult should be returned with the current media item when the command completed.
|