belongs to Maven artifact androidx.mediarouter:mediarouter:1.0.0-alpha4

RouteMediaPlayer

public abstract class RouteMediaPlayer
extends BaseMediaPlayer

java.lang.Object
   ↳ androidx.media2.BaseMediaPlayer
     ↳ androidx.mediarouter.media.RouteMediaPlayer


RouteMediaPlayer is the abstract class representing playback happens on the outside of the device through MediaRouter

If you use this to the MediaSession2 followings would happen.

  • Session wouldn't handle audio focus
  • Session would dispatch volume change event to the player instead of changing device volume

Summary

Constants

int VOLUME_CONTROL_ABSOLUTE

The volume control uses an absolute value.

int VOLUME_CONTROL_FIXED

The volume is fixed and can not be modified.

int VOLUME_CONTROL_RELATIVE

The volume control uses relative adjustment via adjustPlayerVolume(int).

Inherited constants

Public constructors

RouteMediaPlayer()

Public methods

final void adjustPlayerVolume(int direction)

Adjust player volume with the direction.

final float getMaxPlayerVolume()
final float getPlayerVolume()

Returns the current volume of this player to this player.

final int getVolumeControlType()

Gets the volume type.

final void notifyBufferingStateChanged(DataSourceDesc2 dsd, int state)

Notifies that buffering state of a data source is changed.

final void notifyCurrentDataSourceChanged()

Notifies the current data source.

final void notifyMediaPrepared(DataSourceDesc2 dsd)

Notifies that a data source is prepared.

final void notifyPlaybackCompleted()

Notifies that the playback is completed.

final void notifyPlaybackSpeedChanged()

Notifies the current playback speed.

final void notifyPlayerStateChanged()

Notifies the current player state.

final void notifyPlayerVolumeChanged()

Notifies the current player volume.

final void notifySeekCompleted(long position)

Notifies that buffering state of a data source is changed.

final void registerPlayerEventCallback(Executor executor, BaseMediaPlayer.PlayerEventCallback callback)

Adds a callback to be notified of events for this player.

final void setPlayerVolume(float volume)

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

final void unregisterPlayerEventCallback(BaseMediaPlayer.PlayerEventCallback callback)

Removes a previously registered callback for player events.

final void updateRouteInfo(MediaRouter.RouteInfo route)

Updates routes info.

Inherited methods

Constants

VOLUME_CONTROL_ABSOLUTE

public static final int VOLUME_CONTROL_ABSOLUTE

The volume control uses an absolute value. It may be adjusted using adjustPlayerVolume(int) or set directly using setPlayerVolume(float).

Constant Value: 2 (0x00000002)

VOLUME_CONTROL_FIXED

public static final int VOLUME_CONTROL_FIXED

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

Constant Value: 0 (0x00000000)

VOLUME_CONTROL_RELATIVE

public static final int VOLUME_CONTROL_RELATIVE

The volume control uses relative adjustment via adjustPlayerVolume(int). Attempts to set the volume to a specific value should be ignored.

Constant Value: 1 (0x00000001)

Public constructors

RouteMediaPlayer

public RouteMediaPlayer ()

Public methods

adjustPlayerVolume

public final void adjustPlayerVolume (int direction)

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

Default implement adjust volume by 1

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.

getMaxPlayerVolume

public final float getMaxPlayerVolume ()

Returns
float the maximum volume that can be used in setPlayerVolume(float).

getPlayerVolume

public final float getPlayerVolume ()

Returns the current volume of this player to this player. Note that it does not take into account the associated stream volume.

Returns
float the player volume.

getVolumeControlType

public final int getVolumeControlType ()

Gets the volume type.

This shouldn't be changed after instantiation.

Returns
int one of the volume type

notifyBufferingStateChanged

public final void notifyBufferingStateChanged (DataSourceDesc2 dsd, 
                int state)

Notifies that buffering state of a data source is changed.

Registered BaseMediaPlayer.PlayerEventCallback would receive this event through the BaseMediaPlayer.PlayerEventCallback.onBufferingStateChanged(BaseMediaPlayer, DataSourceDesc2, int).

Parameters
dsd DataSourceDesc2: dsd to notify

state int: new buffering state

notifyCurrentDataSourceChanged

public final void notifyCurrentDataSourceChanged ()

Notifies the current data source. Call this API when the current data soruce is changed.

Registered BaseMediaPlayer.PlayerEventCallback would receive this event through the BaseMediaPlayer.PlayerEventCallback.onCurrentDataSourceChanged(BaseMediaPlayer, DataSourceDesc2).

notifyMediaPrepared

public final void notifyMediaPrepared (DataSourceDesc2 dsd)

Notifies that a data source is prepared.

Registered BaseMediaPlayer.PlayerEventCallback would receive this event through the BaseMediaPlayer.PlayerEventCallback.onCurrentDataSourceChanged(BaseMediaPlayer, DataSourceDesc2) with null DataSourceDesc2.

Parameters
dsd DataSourceDesc2: prepared dsd

notifyPlaybackCompleted

public final void notifyPlaybackCompleted ()

Notifies that the playback is completed. Call this API when no other source is about to be played next (i.e. playback reached the end of the list of sources to play).

Registered BaseMediaPlayer.PlayerEventCallback would receive this event through the BaseMediaPlayer.PlayerEventCallback.onCurrentDataSourceChanged(BaseMediaPlayer, DataSourceDesc2) with null DataSourceDesc2.

notifyPlaybackSpeedChanged

public final void notifyPlaybackSpeedChanged ()

Notifies the current playback speed. Call this API when the current playback speed is changed.

Registered BaseMediaPlayer.PlayerEventCallback would receive this event through the BaseMediaPlayer.PlayerEventCallback.onPlaybackSpeedChanged(BaseMediaPlayer, float).

notifyPlayerStateChanged

public final void notifyPlayerStateChanged ()

Notifies the current player state. Call this API when the current player state is changed.

Registered BaseMediaPlayer.PlayerEventCallback would receive this event through the BaseMediaPlayer.PlayerEventCallback.onPlayerStateChanged(BaseMediaPlayer, int).

notifyPlayerVolumeChanged

public final void notifyPlayerVolumeChanged ()

Notifies the current player volume. Call this API when the current playback volume is changed.

notifySeekCompleted

public final void notifySeekCompleted (long position)

Notifies that buffering state of a data source is changed.

Registered BaseMediaPlayer.PlayerEventCallback would receive this event through the BaseMediaPlayer.PlayerEventCallback.onSeekCompleted(BaseMediaPlayer, long)

Parameters
position long: seek position. May be differ with the position specified by BaseMediaPlayer.seekTo(long).

registerPlayerEventCallback

public final void registerPlayerEventCallback (Executor executor, 
                BaseMediaPlayer.PlayerEventCallback callback)

Adds a callback to be notified of events for this player.

Parameters
executor Executor: the Executor to be used for the events.

callback BaseMediaPlayer.PlayerEventCallback: the callback to receive the events.

setPlayerVolume

public final void setPlayerVolume (float 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.0f indicates muting, a value of 1.0f is the nominal unattenuated and unamplified gain. See getMaxPlayerVolume() for the volume range supported by this player.

Parameters
volume float: a value between 0.0f and getMaxPlayerVolume().

unregisterPlayerEventCallback

public final void unregisterPlayerEventCallback (BaseMediaPlayer.PlayerEventCallback callback)

Removes a previously registered callback for player events.

Parameters
callback BaseMediaPlayer.PlayerEventCallback: the callback to remove

updateRouteInfo

public final void updateRouteInfo (MediaRouter.RouteInfo route)

Updates routes info. If the same route has already set, it only notifies volume changes.

Parameters
route MediaRouter.RouteInfo: route