Added in API level 21

TransportControls

class TransportControls
kotlin.Any
   ↳ 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
Unit

Start fast forwarding.

Unit

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

Unit

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

Unit
playFromMediaId(mediaId: String!, extras: Bundle!)

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

Unit
playFromSearch(query: String!, extras: Bundle!)

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

Unit
playFromUri(uri: Uri!, extras: Bundle!)

Request that the player start playback for a specific Uri.

Unit

Request that the player prepare its playback.

Unit
prepareFromMediaId(mediaId: String!, extras: Bundle!)

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

Unit
prepareFromSearch(query: String!, extras: Bundle!)

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

Unit
prepareFromUri(uri: Uri!, extras: Bundle!)

Request that the player prepare playback for a specific Uri.

Unit

Start rewinding.

Unit
seekTo(pos: Long)

Move to a new location in the media stream.

Unit

Send a custom action back for the MediaSession to perform.

Unit
sendCustomAction(action: String, args: Bundle?)

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

Unit

Sets the playback speed.

Unit
setRating(rating: Rating!)

Rate the current content.

Unit

Skip to the next item.

Unit

Skip to the previous item.

Unit

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

Unit

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

Public methods

fastForward

Added in API level 21
fun fastForward(): Unit

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

pause

Added in API level 21
fun pause(): Unit

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

play

Added in API level 21
fun play(): Unit

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

playFromMediaId

Added in API level 21
fun playFromMediaId(
    mediaId: String!,
    extras: Bundle!
): Unit

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
fun playFromSearch(
    query: String!,
    extras: Bundle!
): Unit

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
fun playFromUri(
    uri: Uri!,
    extras: Bundle!
): Unit

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
fun prepare(): Unit

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
fun prepareFromMediaId(
    mediaId: String!,
    extras: Bundle!
): Unit

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 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
fun prepareFromSearch(
    query: String!,
    extras: Bundle!
): Unit

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 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
fun prepareFromUri(
    uri: Uri!,
    extras: Bundle!
): Unit

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 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
fun rewind(): Unit

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

seekTo

Added in API level 21
fun seekTo(pos: Long): Unit

Move to a new location in the media stream.

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

sendCustomAction

Added in API level 21
fun sendCustomAction(
    customAction: PlaybackState.CustomAction,
    args: Bundle?
): Unit

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
fun sendCustomAction(
    action: String,
    args: Bundle?
): Unit

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
fun setPlaybackSpeed(speed: Float): Unit

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
Exceptions
java.lang.IllegalArgumentException if the speed is equal to zero.

setRating

Added in API level 21
fun setRating(rating: Rating!): Unit

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
fun skipToNext(): Unit

Skip to the next item.

skipToPrevious

Added in API level 21
fun skipToPrevious(): Unit

Skip to the previous item.

skipToQueueItem

Added in API level 21
fun skipToQueueItem(id: Long): Unit

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.

stop

Added in API level 21
fun stop(): Unit

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