RemoteSessionPlayer

Added in 1.0.0
Deprecated in 1.3.0

public abstract class RemoteSessionPlayer extends 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

static final int

The volume control uses an absolute value.

static final int

The volume is fixed and can not be modified.

static final int

The volume control uses relative adjustment via adjustVolume.

Public constructors

Public methods

abstract @NonNull Future<SessionPlayer.PlayerResult>
adjustVolume(int direction)

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 @NonNull Future<SessionPlayer.PlayerResult>
setVolume(int volume)

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

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

static final int

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

static final int

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

static final int

Buffering state is unknown.

static final int

Media item index is invalid.

static final int

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

static final int

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

static final int

State when the player's playback is paused

static final int

State when the player's playback is ongoing

static final int

Playing media list will be repeated.

static final int

Playback of the playing media group will be repeated.

static final int

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

static final int

Playback of the current playing media item will be repeated.

static final int

Media list will be played in shuffled order.

static final int

Media group will be played in shuffled order.

static final int

Media list will be played in order.

static final long
UNKNOWN_TIME = -9223372036854775808

Value indicating the time is unknown

Inherited methods

From java.io.Closeable
abstract void
From androidx.media2.common.SessionPlayer
abstract @NonNull ListenableFuture<SessionPlayer.PlayerResult>
addPlaylistItem(int index, @NonNull MediaItem item)

Adds the media item to the playlist at the index.

void

Removes all existing references to callbacks and executors.

@NonNull ListenableFuture<SessionPlayer.PlayerResult>

Deselects the TrackInfo for the current media item.

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

final @NonNull List<Pair<SessionPlayer.PlayerCallbackExecutor>>

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

abstract @Nullable 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 @Nullable List<MediaItem>

Gets the playlist.

abstract @Nullable MediaMetadata

Gets the playlist metadata.

abstract @IntRange(from = -1) int

Gets the previous item index in the playlist.

abstract int

Gets the repeat mode.

@Nullable SessionPlayer.TrackInfo
getSelectedTrack(int trackType)

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

abstract int

Gets the shuffle mode.

@NonNull List<SessionPlayer.TrackInfo>

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

@NonNull VideoSize

Gets the size of the video.

@NonNull ListenableFuture<SessionPlayer.PlayerResult>
movePlaylistItem(
    @IntRange(from = 0) int fromIndex,
    @IntRange(from = 0) int toIndex
)

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

abstract @NonNull ListenableFuture<SessionPlayer.PlayerResult>

Pauses playback.

abstract @NonNull ListenableFuture<SessionPlayer.PlayerResult>

Starts or resumes playback.

abstract @NonNull ListenableFuture<SessionPlayer.PlayerResult>

Prepares the media items for playback.

final void

Register PlayerCallback to listen changes.

abstract @NonNull ListenableFuture<SessionPlayer.PlayerResult>
removePlaylistItem(@IntRange(from = 0) int index)

Removes the media item from the playlist

abstract @NonNull ListenableFuture<SessionPlayer.PlayerResult>

Replaces the media item at index in the playlist.

abstract @NonNull ListenableFuture<SessionPlayer.PlayerResult>
seekTo(long position)

Seeks to the specified position.

@NonNull ListenableFuture<SessionPlayer.PlayerResult>

Selects the TrackInfo for the current media item.

abstract @NonNull ListenableFuture<SessionPlayer.PlayerResult>

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

abstract @NonNull ListenableFuture<SessionPlayer.PlayerResult>

Sets a MediaItem for playback.

abstract @NonNull ListenableFuture<SessionPlayer.PlayerResult>
setPlaybackSpeed(float playbackSpeed)

Sets the playback speed.

abstract @NonNull ListenableFuture<SessionPlayer.PlayerResult>
setPlaylist(
    @NonNull List<MediaItem> list,
    @Nullable MediaMetadata metadata
)

Sets a list of MediaItem with metadata.

abstract @NonNull ListenableFuture<SessionPlayer.PlayerResult>
setRepeatMode(int repeatMode)

Sets the repeat mode.

abstract @NonNull ListenableFuture<SessionPlayer.PlayerResult>
setShuffleMode(int shuffleMode)

Sets the shuffle mode.

@NonNull ListenableFuture<SessionPlayer.PlayerResult>

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

abstract @NonNull ListenableFuture<SessionPlayer.PlayerResult>

Skips to the next item in the playlist.

abstract @NonNull ListenableFuture<SessionPlayer.PlayerResult>
skipToPlaylistItem(@IntRange(from = 0) int index)

Skips to the item in the playlist at the index.

abstract @NonNull ListenableFuture<SessionPlayer.PlayerResult>

Skips to the previous item in the playlist.

final void

Unregister the previously registered PlayerCallback.

abstract @NonNull 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
public static final int VOLUME_CONTROL_ABSOLUTE = 2

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
public static final int VOLUME_CONTROL_FIXED = 0

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
public static final int VOLUME_CONTROL_RELATIVE = 1

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
public RemoteSessionPlayer()

Public methods

adjustVolume

Added in 1.0.0
Deprecated in 1.3.0
public abstract @NonNull Future<SessionPlayer.PlayerResultadjustVolume(int direction)

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

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

Returns
@NonNull Future<SessionPlayer.PlayerResult>

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

getMaxVolume

Added in 1.0.0
Deprecated in 1.3.0
public abstract int getMaxVolume()

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
public abstract int getVolume()

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
public abstract int getVolumeControlType()

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
public abstract @NonNull Future<SessionPlayer.PlayerResultsetVolume(int volume)

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

a value between 0 and getMaxVolume.

Returns
@NonNull Future<SessionPlayer.PlayerResult>

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