Most visited

Recently visited

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

From class java.lang.Object

Public methods

fastForward

Added in API level 21
void fastForward ()

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

pause

Added in API level 21
void pause ()

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

play

Added in API level 21
void play ()

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

playFromMediaId

Added in API level 21
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
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
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
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 STATE_PAUSED. Afterwards, play() can be called to start playback.

prepareFromMediaId

Added in API level 24
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 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
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 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
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 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
void rewind ()

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

seekTo

Added in API level 21
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
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.
args Bundle: Optional arguments to supply to the MediaSession for this custom action.

sendCustomAction

Added in API level 21
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.
args Bundle: Optional arguments to supply to the MediaSession for this custom action.

See also:

setRating

Added in API level 21
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 getRatingType().

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

skipToNext

Added in API level 21
void skipToNext ()

Skip to the next item.

skipToPrevious

Added in API level 21
void skipToPrevious ()

Skip to the previous item.

skipToQueueItem

Added in API level 21
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
void stop ()

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

Hooray!