Skip to content

Most visited

Recently visited

navigation

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 setRepeatMode(int repeatMode)

Set the repeat mode for this session.

void setShuffleModeEnabled(boolean enabled)

Set the shuffle mode for this session.

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

setRepeatMode

void setRepeatMode (int repeatMode)

Set the repeat mode for this session.

Parameters
repeatMode int: The repeat mode. Must be one of the followings: REPEAT_MODE_NONE, REPEAT_MODE_ONE, REPEAT_MODE_ALL

setShuffleModeEnabled

void setShuffleModeEnabled (boolean enabled)

Set the shuffle mode for this session.

Parameters
enabled boolean: true to enable the shuffle mode, false to disable.

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.

This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a one-minute survey?
Help us improve Android tools and documentation.