Added in API level 21

MediaController.TransportControls

public final class MediaController.TransportControls
extends Object

java.lang.Object
   ↳ android.media.session.MediaController.TransportControls


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

Summary

Public methods

void fastForward()

Start fast forwarding.

void pause()

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

void play()

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

void playFromMediaId(String mediaId, Bundle extras)

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

void playFromSearch(String query, Bundle extras)

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

void playFromUri(Uri uri, Bundle extras)

Request that the player start playback for a specific Uri.

void prepare()

Request that the player prepare its playback.

void prepareFromMediaId(String mediaId, Bundle extras)

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

void prepareFromSearch(String query, Bundle extras)

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

void prepareFromUri(Uri uri, Bundle extras)

Request that the player prepare playback for a specific Uri.

void rewind()

Start rewinding.

void seekTo(long pos)

Move to a new location in the media stream.

void sendCustomAction(PlaybackState.CustomAction customAction, Bundle args)

Send a custom action back for the MediaSession to perform.

void sendCustomAction(String action, Bundle args)

Send the id and args from a custom action back for the MediaSession to perform.

void setPlaybackSpeed(float speed)

Sets the playback speed.

void setRating(Rating rating)

Rate the current content.

void skipToNext()

Skip to the next item.

void skipToPrevious()

Skip to the previous item.

void skipToQueueItem(long id)

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

void stop()

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

Inherited methods

Public methods

fastForward

Added in API level 21
public void fastForward ()

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

pause

Added in API level 21
public void pause ()

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

play

Added in API level 21
public void play ()

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

playFromMediaId

Added in API level 21
public void playFromMediaId (String mediaId, 
                Bundle extras)

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

Parameters
mediaId String: The id of the requested media.

extras Bundle: Optional extras that can include extra information about the media item to be played.

playFromSearch

Added in API level 21
public void playFromSearch (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 String: The search query.

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

playFromUri

Added in API level 23
public void playFromUri (Uri uri, 
                Bundle extras)

Request that the player start playback for a specific Uri.

Parameters
uri Uri: The URI of the requested media.

extras Bundle: Optional extras that can include extra information about the media item to be played.

prepare

Added in API level 24
public void prepare ()

Request that the player prepare its playback. In other words, other sessions can continue to play during the preparation of this session. This method can be used to speed up the start of the playback. Once the preparation is done, the session will change its playback state to PlaybackState#STATE_PAUSED. Afterwards, play() can be called to start playback.

prepareFromMediaId

Added in API level 24
public void prepareFromMediaId (String mediaId, 
                Bundle extras)

Request that the player prepare playback for a specific media id. In other words, other sessions can continue to play during the preparation of this session. This method can be used to speed up the start of the playback. Once the preparation is done, the session will change its playback state to PlaybackState#STATE_PAUSED. Afterwards, play() can be called to start playback. If the preparation is not needed, playFromMediaId(String, Bundle) can be directly called without this method.

Parameters
mediaId String: The id of the requested media.

extras Bundle: Optional extras that can include extra information about the media item to be prepared.

prepareFromSearch

Added in API level 24
public void prepareFromSearch (String query, 
                Bundle extras)

Request that the player prepare playback for a specific search query. An empty or null query should be treated as a request to prepare any music. In other words, other sessions can continue to play during the preparation of this session. This method can be used to speed up the start of the playback. Once the preparation is done, the session will change its playback state to PlaybackState#STATE_PAUSED. Afterwards, play() can be called to start playback. If the preparation is not needed, playFromSearch(String, Bundle) can be directly called without this method.

Parameters
query String: The search query.

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

prepareFromUri

Added in API level 24
public void prepareFromUri (Uri uri, 
                Bundle extras)

Request that the player prepare playback for a specific Uri. In other words, other sessions can continue to play during the preparation of this session. This method can be used to speed up the start of the playback. Once the preparation is done, the session will change its playback state to PlaybackState#STATE_PAUSED. Afterwards, play() can be called to start playback. If the preparation is not needed, playFromUri(Uri, Bundle) can be directly called without this method.

Parameters
uri Uri: The URI of the requested media.

extras Bundle: Optional extras that can include extra information about the media item to be prepared.

rewind

Added in API level 21
public void rewind ()

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

seekTo

Added in API level 21
public void seekTo (long pos)

Move to a new location in the media stream.

Parameters
pos long: Position to move to, in milliseconds.

sendCustomAction

Added in API level 21
public void sendCustomAction (PlaybackState.CustomAction customAction, 
                Bundle args)

Send a custom action back for the MediaSession to perform.

Parameters
customAction PlaybackState.CustomAction: The action to perform. This value cannot be null.

args Bundle: Optional arguments to supply to the MediaSession for this custom action. This value may be null.

sendCustomAction

Added in API level 21
public void sendCustomAction (String action, 
                Bundle args)

Send the id and args from a custom action back for the MediaSession to perform.

Parameters
action String: The action identifier of the PlaybackState.CustomAction as specified by the MediaSession. This value cannot be null.

args Bundle: Optional arguments to supply to the MediaSession for this custom action. This value may be null.

setPlaybackSpeed

Added in API level 29
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 float: The playback speed

Throws
IllegalArgumentException if the speed is equal to zero.

setRating

Added in API level 21
public void setRating (Rating rating)

Rate the current content. This will cause the rating to be set for the current user. The Rating type must match the type returned by MediaController.getRatingType().

Parameters
rating Rating: The rating to set for the current content

skipToNext

Added in API level 21
public void skipToNext ()

Skip to the next item.

skipToPrevious

Added in API level 21
public void skipToPrevious ()

Skip to the previous item.

skipToQueueItem

Added in API level 21
public void skipToQueueItem (long id)

Play 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.

Parameters
id long

stop

Added in API level 21
public void stop ()

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