public abstract class

MediaControllerCompat.TransportControls

extends java.lang.Object

 java.lang.Object

↳androidx.media3.session.legacy.MediaControllerCompat.TransportControls

Overview

Interface for controlling media playback on a session. This allows an app to send media transport commands to the session.

Summary

Fields
public static final java.lang.StringEXTRA_LEGACY_STREAM_TYPE

Used as an integer extra field in MediaControllerCompat.TransportControls.playFromMediaId(String, Bundle) or MediaControllerCompat.TransportControls.prepareFromMediaId(String, Bundle) to indicate the stream type to be used by the media player when playing or preparing the specified media id.

Methods
public abstract voidfastForward()

Starts fast forwarding.

public abstract voidpause()

Request that the player pause its playback and stay at its current position.

public abstract voidplay()

Request that the player start its playback at its current position.

public abstract voidplayFromMediaId(java.lang.String mediaId, Bundle extras)

Request that the player start playback for a specific media id.

public abstract voidplayFromSearch(java.lang.String query, Bundle extras)

Request that the player start playback for a specific search query.

public abstract voidplayFromUri(Uri uri, Bundle extras)

Request that the player start playback for a specific .

public abstract voidprepare()

Request that the player prepare for playback.

public abstract voidprepareFromMediaId(java.lang.String mediaId, Bundle extras)

Request that the player prepare playback for a specific media id.

public abstract voidprepareFromSearch(java.lang.String query, Bundle extras)

Request that the player prepare playback for a specific search query.

public abstract voidprepareFromUri(Uri uri, Bundle extras)

Request that the player prepare playback for a specific .

public abstract voidrewind()

Starts rewinding.

public abstract voidseekTo(long pos)

Moves to a new location in the media stream.

public abstract voidsendCustomAction(PlaybackStateCompat.CustomAction customAction, Bundle args)

Sends a custom action for the MediaSessionCompat to perform.

public abstract voidsendCustomAction(java.lang.String action, Bundle args)

Sends the id and args from a custom action for the MediaSessionCompat to perform.

public abstract voidsetCaptioningEnabled(boolean enabled)

Enables/disables captioning for this session.

public voidsetPlaybackSpeed(float speed)

Sets the playback speed.

public abstract voidsetRating(RatingCompat rating)

Rates the current content.

public abstract voidsetRating(RatingCompat rating, Bundle extras)

Rates a media item.

public abstract voidsetRepeatMode(int repeatMode)

Sets the repeat mode for this session.

public abstract voidsetShuffleMode(int shuffleMode)

Sets the shuffle mode for this session.

public abstract voidskipToNext()

Skips to the next item.

public abstract voidskipToPrevious()

Skips to the previous item.

public abstract voidskipToQueueItem(long id)

Plays an item with a specific id in the play queue.

public abstract voidstop()

Request that the player stop its playback; it may clear its state in whatever way is appropriate.

from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Fields

public static final java.lang.String EXTRA_LEGACY_STREAM_TYPE

Deprecated: Use MediaConstants.TRANSPORT_CONTROLS_EXTRAS_KEY_LEGACY_STREAM_TYPE instead.

Used as an integer extra field in MediaControllerCompat.TransportControls.playFromMediaId(String, Bundle) or MediaControllerCompat.TransportControls.prepareFromMediaId(String, Bundle) to indicate the stream type to be used by the media player when playing or preparing the specified media id. See AudioManager for a list of stream types.

Methods

public abstract void prepare()

Request that the player prepare for playback. This can decrease the time it takes to start playback when a play command is received. Preparation is not required. You can call MediaControllerCompat.TransportControls.play() without calling this method beforehand.

public abstract void prepareFromMediaId(java.lang.String mediaId, Bundle extras)

Request that the player prepare playback for a specific media id. This can decrease the time it takes to start playback when a play command is received. Preparation is not required. You can call MediaControllerCompat.TransportControls.playFromMediaId(String, Bundle) without calling this method beforehand.

Parameters:

mediaId: The id of the requested media.
extras: Optional extras that can include extra information about the media item to be prepared.

public abstract void prepareFromSearch(java.lang.String query, Bundle extras)

Request that the player prepare playback for a specific search query. This can decrease the time it takes to start playback when a play command is received. An empty or null query should be treated as a request to prepare any music. Preparation is not required. You can call MediaControllerCompat.TransportControls.playFromSearch(String, Bundle) without calling this method beforehand.

Parameters:

query: The search query.
extras: Optional extras that can include extra information about the query.

public abstract void prepareFromUri(Uri uri, Bundle extras)

Request that the player prepare playback for a specific . This can decrease the time it takes to start playback when a play command is received. Preparation is not required. You can call MediaControllerCompat.TransportControls.playFromUri(Uri, Bundle) without calling this method beforehand.

Parameters:

uri: The URI of the requested media.
extras: Optional extras that can include extra information about the media item to be prepared.

public abstract void play()

Request that the player start its playback at its current position.

public abstract void playFromMediaId(java.lang.String mediaId, Bundle extras)

Request that the player start playback for a specific media id.

Parameters:

mediaId: The id of the requested media.
extras: Optional extras that can include extra information about the media item to be played.

public abstract void playFromSearch(java.lang.String query, Bundle extras)

Request that the player start playback for a specific search query. An empty or null query should be treated as a request to play any music.

Parameters:

query: The search query.
extras: Optional extras that can include extra information about the query.

public abstract void playFromUri(Uri uri, Bundle extras)

Request that the player start playback for a specific .

Parameters:

uri: The URI of the requested media.
extras: Optional extras that can include extra information about the media item to be played.

public abstract void skipToQueueItem(long id)

Plays an item with a specific id in the play queue. If you specify an id that is not in the play queue, the behavior is undefined.

public abstract void pause()

Request that the player pause its playback and stay at its current position.

public abstract void stop()

Request that the player stop its playback; it may clear its state in whatever way is appropriate.

public abstract void seekTo(long pos)

Moves to a new location in the media stream.

Parameters:

pos: Position to move to, in milliseconds.

public abstract void fastForward()

Starts fast forwarding. If playback is already fast forwarding this may increase the rate.

public abstract void skipToNext()

Skips to the next item.

public abstract void rewind()

Starts rewinding. If playback is already rewinding this may increase the rate.

public abstract void skipToPrevious()

Skips to the previous item.

public abstract void setRating(RatingCompat rating)

Rates the current content. This will cause the rating to be set for the current user. The rating type of the given RatingCompat must match the type returned by MediaControllerCompat.getRatingType().

Parameters:

rating: The rating to set for the current content

public abstract void setRating(RatingCompat rating, Bundle extras)

Rates a media item. This will cause the rating to be set for the specific media item. The rating type of the given RatingCompat must match the type returned by MediaControllerCompat.getRatingType().

Parameters:

rating: The rating to set for the media item.
extras: Optional arguments that can include information about the media item to be rated.

See also: MediaSessionCompat.ARGUMENT_MEDIA_ATTRIBUTE, MediaSessionCompat.ARGUMENT_MEDIA_ATTRIBUTE_VALUE

public void setPlaybackSpeed(float speed)

Sets the playback speed. A value of 1.0f is the default playback value, and a negative value indicates reverse playback. 0.0f is not allowed.

Parameters:

speed: The playback speed

public abstract void setCaptioningEnabled(boolean enabled)

Enables/disables captioning for this session.

Parameters:

enabled: true to enable captioning, false to disable.

public abstract void setRepeatMode(int repeatMode)

Sets the repeat mode for this session.

Parameters:

repeatMode: The repeat mode. Must be one of the following: PlaybackStateCompat.REPEAT_MODE_NONE, PlaybackStateCompat.REPEAT_MODE_ONE, PlaybackStateCompat.REPEAT_MODE_ALL, PlaybackStateCompat.REPEAT_MODE_GROUP

public abstract void setShuffleMode(int shuffleMode)

Sets the shuffle mode for this session.

Parameters:

shuffleMode: The shuffle mode. Must be one of the following: PlaybackStateCompat.SHUFFLE_MODE_NONE, PlaybackStateCompat.SHUFFLE_MODE_ALL, PlaybackStateCompat.SHUFFLE_MODE_GROUP

public abstract void sendCustomAction(PlaybackStateCompat.CustomAction customAction, Bundle args)

Sends a custom action for the MediaSessionCompat to perform.

Parameters:

customAction: The action to perform.
args: Optional arguments to supply to the MediaSessionCompat for this custom action.

public abstract void sendCustomAction(java.lang.String action, Bundle args)

Sends the id and args from a custom action for the MediaSessionCompat to perform.

Parameters:

action: The action identifier of the PlaybackStateCompat.CustomAction as specified by the MediaSessionCompat.
args: Optional arguments to supply to the MediaSessionCompat for this custom action.

See also: MediaControllerCompat.TransportControls.sendCustomAction(PlaybackStateCompat.CustomAction, Bundle), MediaSessionCompat.ACTION_FLAG_AS_INAPPROPRIATE, MediaSessionCompat.ACTION_SKIP_AD, MediaSessionCompat.ACTION_FOLLOW, MediaSessionCompat.ACTION_UNFOLLOW