RemoteSessionPlayer

Added in 1.0.0
Deprecated in 1.3.0

abstract class RemoteSessionPlayer : SessionPlayer


Base interface for all remote media players that want media session and playback happens on the remote device through MediaRouter.

If you use this to the MediaSession, session would dispatch incoming volume change event to the player instead of changing device stream volume.

Summary

Nested types

This class is deprecated.

androidx.media2 is deprecated.

Constants

const Int

The volume control uses an absolute value.

const Int

The volume is fixed and can not be modified.

const Int

The volume control uses relative adjustment via adjustVolume.

Public constructors

Public functions

abstract Future<SessionPlayer.PlayerResult!>
adjustVolume(direction: Int)

Adjusts player volume with the direction.

abstract Int

Gets the maximum volume that can be used in setVolume.

abstract Int

Gets the current volume of this player to this player.

abstract Int

Gets the volume type.

abstract Future<SessionPlayer.PlayerResult!>
setVolume(volume: Int)

Sets the volume of the audio of the media to play, expressed as a linear multiplier on the audio samples.

Inherited Constants

From androidx.media2.common.SessionPlayer
const Int

Buffering state indicating the player is buffering but enough has been buffered for this player to be able to play the content.

const Int

Buffering state indicating the player is buffering, but the player is currently starved for data, and cannot play.

const Int

Buffering state indicating the player is done buffering, and the remainder of the content is available for playback.

const Int

Buffering state is unknown.

const Int

Media item index is invalid.

const Int

State when the player is in error state and cannot be recovered self.

const Int

State when the player is idle, and needs configuration to start playback.

const Int

State when the player's playback is paused

const Int

State when the player's playback is ongoing

const Int

Playing media list will be repeated.

const Int

Playback of the playing media group will be repeated.

const Int

Playback will be stopped at the end of the playing media list.

const Int

Playback of the current playing media item will be repeated.

const Int

Media list will be played in shuffled order.

const Int

Media group will be played in shuffled order.

const Int

Media list will be played in order.

const Long
UNKNOWN_TIME = -9223372036854775808

Value indicating the time is unknown

Inherited functions

From java.io.Closeable
abstract Unit
From androidx.media2.common.SessionPlayer
abstract ListenableFuture<SessionPlayer.PlayerResult!>
addPlaylistItem(index: Int, item: MediaItem)

Adds the media item to the playlist at the index.

Unit

Removes all existing references to callbacks and executors.

ListenableFuture<SessionPlayer.PlayerResult!>

Deselects the TrackInfo for the current media item.

abstract AudioAttributesCompat?

Gets the AudioAttributesCompat that media player has.

abstract Long

Gets the position for how much has been buffered, or UNKNOWN_TIME if unknown.

abstract Int

Returns the current buffering state of the player.

(Mutable)List<Pair<SessionPlayer.PlayerCallback!, Executor!>!>

Gets the callbacks with executors for subclasses to notify player events.

abstract MediaItem?

Gets the current media item, which is currently playing or would be played with later play.

abstract @IntRange(from = -1) Int

Gets the index of current media item in playlist.

abstract Long

Gets the current playback position.

abstract Long

Gets the duration of the current media item, or UNKNOWN_TIME if unknown.

abstract @IntRange(from = -1) Int

Gets the next item index in the playlist.

abstract Float

Gets the actual playback speed to be used by the player when playing.

abstract Int

Gets the current player state.

abstract (Mutable)List<MediaItem!>?

Gets the playlist.

abstract MediaMetadata?

Gets the playlist metadata.

abstract @IntRange(from = -1) Int

Gets the previous item index in the playlist.

abstract Int

Gets the repeat mode.

SessionPlayer.TrackInfo?
getSelectedTrack(trackType: Int)

Gets currently selected track's TrackInfo for the given track type.

abstract Int

Gets the shuffle mode.

(Mutable)List<SessionPlayer.TrackInfo!>

Gets the full list of selected and unselected tracks that the media contains.

VideoSize

Gets the size of the video.

ListenableFuture<SessionPlayer.PlayerResult!>
movePlaylistItem(
    fromIndex: @IntRange(from = 0) Int,
    toIndex: @IntRange(from = 0) Int
)

Moves the media item at fromIdx to toIdx in the playlist.

abstract ListenableFuture<SessionPlayer.PlayerResult!>

Pauses playback.

abstract ListenableFuture<SessionPlayer.PlayerResult!>

Starts or resumes playback.

abstract ListenableFuture<SessionPlayer.PlayerResult!>

Prepares the media items for playback.

Unit
registerPlayerCallback(
    executor: Executor,
    callback: SessionPlayer.PlayerCallback
)

Register PlayerCallback to listen changes.

abstract ListenableFuture<SessionPlayer.PlayerResult!>
removePlaylistItem(index: @IntRange(from = 0) Int)

Removes the media item from the playlist

abstract ListenableFuture<SessionPlayer.PlayerResult!>

Replaces the media item at index in the playlist.

abstract ListenableFuture<SessionPlayer.PlayerResult!>
seekTo(position: Long)

Seeks to the specified position.

ListenableFuture<SessionPlayer.PlayerResult!>

Selects the TrackInfo for the current media item.

abstract ListenableFuture<SessionPlayer.PlayerResult!>

Sets the AudioAttributesCompat to be used during the playback of the media.

abstract ListenableFuture<SessionPlayer.PlayerResult!>

Sets a MediaItem for playback.

abstract ListenableFuture<SessionPlayer.PlayerResult!>
setPlaybackSpeed(playbackSpeed: Float)

Sets the playback speed.

abstract ListenableFuture<SessionPlayer.PlayerResult!>

Sets a list of MediaItem with metadata.

abstract ListenableFuture<SessionPlayer.PlayerResult!>
setRepeatMode(repeatMode: Int)

Sets the repeat mode.

abstract ListenableFuture<SessionPlayer.PlayerResult!>
setShuffleMode(shuffleMode: Int)

Sets the shuffle mode.

ListenableFuture<SessionPlayer.PlayerResult!>
setSurface(surface: Surface?)

Sets the Surface to be used as the sink for the video portion of the media.

abstract ListenableFuture<SessionPlayer.PlayerResult!>

Skips to the next item in the playlist.

abstract ListenableFuture<SessionPlayer.PlayerResult!>
skipToPlaylistItem(index: @IntRange(from = 0) Int)

Skips to the item in the playlist at the index.

abstract ListenableFuture<SessionPlayer.PlayerResult!>

Skips to the previous item in the playlist.

Unit

Unregister the previously registered PlayerCallback.

abstract ListenableFuture<SessionPlayer.PlayerResult!>

Updates the playlist metadata while keeping the playlist as-is.

Constants

VOLUME_CONTROL_ABSOLUTE

Added in 1.0.0
Deprecated in 1.3.0
const val VOLUME_CONTROL_ABSOLUTE = 2: Int

The volume control uses an absolute value. It may be adjusted using adjustVolume or set directly using setVolume.

VOLUME_CONTROL_FIXED

Added in 1.0.0
Deprecated in 1.3.0
const val VOLUME_CONTROL_FIXED = 0: Int

The volume is fixed and can not be modified. Requests to change volume should be ignored.

VOLUME_CONTROL_RELATIVE

Added in 1.0.0
Deprecated in 1.3.0
const val VOLUME_CONTROL_RELATIVE = 1: Int

The volume control uses relative adjustment via adjustVolume. Attempts to set the volume to a specific value should be ignored.

Public constructors

RemoteSessionPlayer

Added in 1.0.0
Deprecated in 1.3.0
RemoteSessionPlayer()

Public functions

adjustVolume

Added in 1.0.0
Deprecated in 1.3.0
abstract fun adjustVolume(direction: Int): Future<SessionPlayer.PlayerResult!>

Adjusts player volume with the direction. Override this API to customize volume change in remote device.

This would be ignored when volume control type is VOLUME_CONTROL_FIXED.

Parameters
direction: Int

direction of the volume changes. Positive value for volume up, negative for volume down.

Returns
Future<SessionPlayer.PlayerResult!>

result of adjusting the volume. Shouldn't be null.

getMaxVolume

Added in 1.0.0
Deprecated in 1.3.0
abstract fun getMaxVolume(): Int

Gets the maximum volume that can be used in setVolume.

Returns
Int

the maximum volume. Shouldn't be negative.

getVolume

Added in 1.0.0
Deprecated in 1.3.0
abstract fun getVolume(): Int

Gets the current volume of this player to this player.

Note that it does not take into account the associated stream volume because the playback is happening outside of the phone device.

Returns
Int

the player volume.

getVolumeControlType

Added in 1.0.0
Deprecated in 1.3.0
abstract fun getVolumeControlType(): Int

Gets the volume type.

This shouldn't be changed after instantiation.

Returns
Int

one of the volume type

setVolume

Added in 1.0.0
Deprecated in 1.3.0
abstract fun setVolume(volume: Int): Future<SessionPlayer.PlayerResult!>

Sets the volume of the audio of the media to play, expressed as a linear multiplier on the audio samples.

Note that this volume is specific to the player, and is separate from stream volume used across the platform.

A value of 0 indicates muting. See getMaxVolume for the volume range supported by this player.

Parameters
volume: Int

a value between 0 and getMaxVolume.

Returns
Future<SessionPlayer.PlayerResult!>

result of setting the volume. Shouldn't be null.