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 |
pause() Request that the player pause its playback and stay at its current position. |
Unit |
play() 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 |
Unit |
prepare() 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 |
Unit |
rewind() Start rewinding. |
Unit |
Move to a new location in the media stream. |
Unit |
sendCustomAction(customAction: PlaybackState.CustomAction, args: Bundle?) Send a custom action back for the |
Unit |
sendCustomAction(action: String, args: Bundle?) Send the id and args from a custom action back for the |
Unit |
setPlaybackSpeed(speed: Float) Sets the playback speed. |
Unit |
Rate the current content. |
Unit |
Skip to the next item. |
Unit |
Skip to the previous item. |
Unit |
skipToQueueItem(id: Long) Play an item with a specific id in the play queue. |
Unit |
stop() Request that the player stop its playback; it may clear its state in whatever way is appropriate. |
Public methods
fastForward
fun fastForward(): Unit
Start fast forwarding. If playback is already fast forwarding this may increase the rate.
pause
fun pause(): Unit
Request that the player pause its playback and stay at its current position.
play
fun play(): Unit
Request that the player start its playback at its current position.
playFromMediaId
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
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
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
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
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
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
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
fun rewind(): Unit
Start rewinding. If playback is already rewinding this may increase the rate.
seekTo
fun seekTo(pos: Long): Unit
Move to a new location in the media stream.
Parameters | |
---|---|
pos |
Long: Position to move to, in milliseconds. |
sendCustomAction
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
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
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
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 |
skipToQueueItem
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
fun stop(): Unit
Request that the player stop its playback; it may clear its state in whatever way is appropriate.