MediaControllerCompat.TransportControls

abstract class MediaControllerCompat.TransportControls


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

Summary

Constants

const String!
EXTRA_LEGACY_STREAM_TYPE = "android.media.session.extra.LEGACY_STREAM_TYPE"

This property is deprecated.

Use TRANSPORT_CONTROLS_EXTRAS_KEY_LEGACY_STREAM_TYPE instead.

Public functions

abstract Unit

Starts fast forwarding.

abstract Unit

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

abstract Unit

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

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

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

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

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

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

Request that the player start playback for a specific Uri.

abstract Unit

Request that the player prepare for playback.

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

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

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

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

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

Request that the player prepare playback for a specific Uri.

abstract Unit

Starts rewinding.

abstract Unit
seekTo(pos: Long)

Moves to a new location in the media stream.

abstract Unit
sendCustomAction(action: String!, args: Bundle!)

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

abstract Unit
sendCustomAction(
    customAction: PlaybackStateCompat.CustomAction!,
    args: Bundle!
)

Sends a custom action for the MediaSessionCompat to perform.

abstract Unit

Enables/disables captioning for this session.

Unit

Sets the playback speed.

abstract Unit

Rates the current content.

abstract Unit
setRating(rating: RatingCompat!, extras: Bundle!)

Rates a media item.

abstract Unit
setRepeatMode(repeatMode: Int)

Sets the repeat mode for this session.

abstract Unit
setShuffleMode(shuffleMode: Int)

Sets the shuffle mode for this session.

abstract Unit

Skips to the next item.

abstract Unit

Skips to the previous item.

abstract Unit

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

abstract Unit

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

Constants

EXTRA_LEGACY_STREAM_TYPE

Added in 1.1.0
Deprecated in 1.4.0
const val EXTRA_LEGACY_STREAM_TYPE = "android.media.session.extra.LEGACY_STREAM_TYPE": String!

Used as an integer extra field in playFromMediaId or prepareFromMediaId 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.

Public functions

fastForward

Added in 1.1.0
abstract fun fastForward(): Unit

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

pause

Added in 1.1.0
abstract fun pause(): Unit

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

play

Added in 1.1.0
abstract fun play(): Unit

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

playFromMediaId

Added in 1.1.0
abstract 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 1.1.0
abstract 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 1.1.0
abstract 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 1.1.0
abstract fun prepare(): Unit

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 play without calling this method beforehand.

prepareFromMediaId

Added in 1.1.0
abstract fun prepareFromMediaId(mediaId: String!, extras: Bundle!): Unit

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 playFromMediaId without calling this method beforehand.

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

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 playFromSearch without calling this method beforehand.

Parameters
query: String!

The search query.

extras: Bundle!

Optional extras that can include extra information about the query.

prepareFromUri

Added in 1.1.0
abstract fun prepareFromUri(uri: Uri!, extras: Bundle!): Unit

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

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

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

seekTo

Added in 1.1.0
abstract fun seekTo(pos: Long): Unit

Moves to a new location in the media stream.

Parameters
pos: Long

Position to move to, in milliseconds.

sendCustomAction

Added in 1.1.0
abstract fun sendCustomAction(action: String!, args: Bundle!): Unit

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

Parameters
action: String!

The action identifier of the PlaybackStateCompat.CustomAction as specified by the MediaSessionCompat.

args: Bundle!

Optional arguments to supply to the MediaSessionCompat for this custom action.

sendCustomAction

Added in 1.1.0
abstract fun sendCustomAction(
    customAction: PlaybackStateCompat.CustomAction!,
    args: Bundle!
): Unit

Sends a custom action for the MediaSessionCompat to perform.

Parameters
customAction: PlaybackStateCompat.CustomAction!

The action to perform.

args: Bundle!

Optional arguments to supply to the MediaSessionCompat for this custom action.

setCaptioningEnabled

Added in 1.1.0
abstract fun setCaptioningEnabled(enabled: Boolean): Unit

Enables/disables captioning for this session.

Parameters
enabled: Boolean

true to enable captioning, false to disable.

setPlaybackSpeed

Added in 1.2.0
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

Throws
java.lang.IllegalArgumentException

if the speed is equal to zero.

setRating

Added in 1.1.0
abstract fun setRating(rating: RatingCompat!): Unit

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

Parameters
rating: RatingCompat!

The rating to set for the current content

setRating

Added in 1.1.0
abstract fun setRating(rating: RatingCompat!, extras: Bundle!): Unit

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

Parameters
rating: RatingCompat!

The rating to set for the media item.

extras: Bundle!

Optional arguments that can include information about the media item to be rated.

setRepeatMode

Added in 1.1.0
abstract fun setRepeatMode(repeatMode: Int): Unit

Sets 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, REPEAT_MODE_GROUP

setShuffleMode

Added in 1.1.0
abstract fun setShuffleMode(shuffleMode: Int): Unit

Sets the shuffle mode for this session.

Parameters
shuffleMode: Int

The shuffle mode. Must be one of the followings: SHUFFLE_MODE_NONE, SHUFFLE_MODE_ALL, SHUFFLE_MODE_GROUP

skipToNext

Added in 1.1.0
abstract fun skipToNext(): Unit

Skips to the next item.

skipToPrevious

Added in 1.1.0
abstract fun skipToPrevious(): Unit

Skips to the previous item.

skipToQueueItem

Added in 1.1.0
abstract fun skipToQueueItem(id: Long): Unit

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.

stop

Added in 1.1.0
abstract fun stop(): Unit

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