# MediaController.TransportControls

Added in[API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

# TransportControls

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/android/media/session/MediaController.TransportControls "View this page in Java")  

```
class TransportControls
```

|---|--------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [kotlin.Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)                                                                                     ||
| ↳ | [android.media.session.MediaController.TransportControls](https://developer.android.com/reference/kotlin/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](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [fastForward](https://developer.android.com/reference/kotlin/android/media/session/MediaController.TransportControls#fastForward())`()` Start fast forwarding.                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [pause](https://developer.android.com/reference/kotlin/android/media/session/MediaController.TransportControls#pause())`()` Request that the player pause its playback and stay at its current position.                                                                                                                                                                                                                                                                                                                                                                                                         |
| [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [play](https://developer.android.com/reference/kotlin/android/media/session/MediaController.TransportControls#play())`()` Request that the player start its playback at its current position.                                                                                                                                                                                                                                                                                                                                                                                                                    |
| [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [playFromMediaId](https://developer.android.com/reference/kotlin/android/media/session/MediaController.TransportControls#playFromMediaId(kotlin.String,%20android.os.Bundle))`(`mediaId:` `[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)!`, `extras:` `[Bundle](https://developer.android.com/reference/kotlin/android/os/Bundle.html#)!`)` Request that the player start playback for a specific media id.                                                                                                                                                                   |
| [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [playFromSearch](https://developer.android.com/reference/kotlin/android/media/session/MediaController.TransportControls#playFromSearch(kotlin.String,%20android.os.Bundle))`(`query:` `[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)!`, `extras:` `[Bundle](https://developer.android.com/reference/kotlin/android/os/Bundle.html#)!`)` Request that the player start playback for a specific search query.                                                                                                                                                                   |
| [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [playFromUri](https://developer.android.com/reference/kotlin/android/media/session/MediaController.TransportControls#playFromUri(android.net.Uri,%20android.os.Bundle))`(`uri:` `[Uri](https://developer.android.com/reference/kotlin/android/net/Uri.html#)!`, `extras:` `[Bundle](https://developer.android.com/reference/kotlin/android/os/Bundle.html#)!`)` Request that the player start playback for a specific[Uri](https://developer.android.com/reference/kotlin/android/net/Uri.html#).                                                                                                                |
| [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [prepare](https://developer.android.com/reference/kotlin/android/media/session/MediaController.TransportControls#prepare())`()` Request that the player prepare its playback.                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [prepareFromMediaId](https://developer.android.com/reference/kotlin/android/media/session/MediaController.TransportControls#prepareFromMediaId(kotlin.String,%20android.os.Bundle))`(`mediaId:` `[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)!`, `extras:` `[Bundle](https://developer.android.com/reference/kotlin/android/os/Bundle.html#)!`)` Request that the player prepare playback for a specific media id.                                                                                                                                                           |
| [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [prepareFromSearch](https://developer.android.com/reference/kotlin/android/media/session/MediaController.TransportControls#prepareFromSearch(kotlin.String,%20android.os.Bundle))`(`query:` `[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)!`, `extras:` `[Bundle](https://developer.android.com/reference/kotlin/android/os/Bundle.html#)!`)` Request that the player prepare playback for a specific search query.                                                                                                                                                           |
| [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [prepareFromUri](https://developer.android.com/reference/kotlin/android/media/session/MediaController.TransportControls#prepareFromUri(android.net.Uri,%20android.os.Bundle))`(`uri:` `[Uri](https://developer.android.com/reference/kotlin/android/net/Uri.html#)!`, `extras:` `[Bundle](https://developer.android.com/reference/kotlin/android/os/Bundle.html#)!`)` Request that the player prepare playback for a specific[Uri](https://developer.android.com/reference/kotlin/android/net/Uri.html#).                                                                                                        |
| [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [rewind](https://developer.android.com/reference/kotlin/android/media/session/MediaController.TransportControls#rewind())`()` Start rewinding.                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [seekTo](https://developer.android.com/reference/kotlin/android/media/session/MediaController.TransportControls#seekTo(kotlin.Long))`(`pos:` `[Long](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html)`)` Move to a new location in the media stream.                                                                                                                                                                                                                                                                                                                                        |
| [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [sendCustomAction](https://developer.android.com/reference/kotlin/android/media/session/MediaController.TransportControls#sendCustomAction(android.media.session.PlaybackState.CustomAction,%20android.os.Bundle))`(`customAction:` `[PlaybackState.CustomAction](https://developer.android.com/reference/kotlin/android/media/session/PlaybackState.CustomAction)`, `args:` `[Bundle](https://developer.android.com/reference/kotlin/android/os/Bundle.html#)?`)` Send a custom action back for the[MediaSession](https://developer.android.com/reference/kotlin/android/media/session/MediaSession)to perform. |
| [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [sendCustomAction](https://developer.android.com/reference/kotlin/android/media/session/MediaController.TransportControls#sendCustomAction(kotlin.String,%20android.os.Bundle))`(`action:` `[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, `args:` `[Bundle](https://developer.android.com/reference/kotlin/android/os/Bundle.html#)?`)` Send the id and args from a custom action back for the[MediaSession](https://developer.android.com/reference/kotlin/android/media/session/MediaSession)to perform.                                                                  |
| [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [setPlaybackSpeed](https://developer.android.com/reference/kotlin/android/media/session/MediaController.TransportControls#setPlaybackSpeed(kotlin.Float))`(`speed:` `[Float](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-float/index.html)`)` Sets the playback speed.                                                                                                                                                                                                                                                                                                                                  |
| [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [setRating](https://developer.android.com/reference/kotlin/android/media/session/MediaController.TransportControls#setRating(android.media.Rating))`(`rating:` `[Rating](https://developer.android.com/reference/kotlin/android/media/Rating.html#)!`)` Rate the current content.                                                                                                                                                                                                                                                                                                                                |
| [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [skipToNext](https://developer.android.com/reference/kotlin/android/media/session/MediaController.TransportControls#skipToNext())`()` Skip to the next item.                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [skipToPrevious](https://developer.android.com/reference/kotlin/android/media/session/MediaController.TransportControls#skipToPrevious())`()` Skip to the previous item.                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [skipToQueueItem](https://developer.android.com/reference/kotlin/android/media/session/MediaController.TransportControls#skipToQueueItem(kotlin.Long))`(`id:` `[Long](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html)`)` Play an item with a specific id in the play queue.                                                                                                                                                                                                                                                                                                                |
| [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [stop](https://developer.android.com/reference/kotlin/android/media/session/MediaController.TransportControls#stop())`()` 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](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
fun fastForward(): Unit
```

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

### pause

Added in[API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
fun pause(): Unit
```

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

### play

Added in[API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
fun play(): Unit
```

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

### playFromMediaId

Added in[API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

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

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

|                                                                                     Parameters                                                                                     ||
|-----------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `mediaId` | [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)!:The id of the requested media.                                                        |
| `extras`  | [Bundle](https://developer.android.com/reference/kotlin/android/os/Bundle.html#)!:Optional extras that can include extra information about the media item to be played. |

### playFromSearch

Added in[API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
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](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)!:The search query.                                                   |
| `extras` | [Bundle](https://developer.android.com/reference/kotlin/android/os/Bundle.html#)!:Optional extras that can include extra information about the query. |

### playFromUri

Added in[API level 23](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

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

Request that the player start playback for a specific[Uri](https://developer.android.com/reference/kotlin/android/net/Uri.html#).

|                                                                                    Parameters                                                                                     ||
|----------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `uri`    | [Uri](https://developer.android.com/reference/kotlin/android/net/Uri.html#)!:The URI of the requested media.                                                            |
| `extras` | [Bundle](https://developer.android.com/reference/kotlin/android/os/Bundle.html#)!:Optional extras that can include extra information about the media item to be played. |

### prepare

Added in[API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
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](https://developer.android.com/reference/kotlin/android/media/session/PlaybackState#STATE_PAUSED:kotlin.Int). Afterwards,[play](https://developer.android.com/reference/kotlin/android/media/session/MediaController.TransportControls#play())can be called to start playback.  

### prepareFromMediaId

Added in[API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
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](https://developer.android.com/reference/kotlin/android/media/session/PlaybackState#STATE_PAUSED:kotlin.Int). Afterwards,[play](https://developer.android.com/reference/kotlin/android/media/session/MediaController.TransportControls#play())can be called to start playback. If the preparation is not needed,[playFromMediaId](https://developer.android.com/reference/kotlin/android/media/session/MediaController.TransportControls#playFromMediaId(kotlin.String,%20android.os.Bundle))can be directly called without this method.

|                                                                                      Parameters                                                                                      ||
|-----------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `mediaId` | [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)!:The id of the requested media.                                                          |
| `extras`  | [Bundle](https://developer.android.com/reference/kotlin/android/os/Bundle.html#)!:Optional extras that can include extra information about the media item to be prepared. |

### prepareFromSearch

Added in[API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
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](https://developer.android.com/reference/kotlin/android/media/session/PlaybackState#STATE_PAUSED:kotlin.Int). Afterwards,[play](https://developer.android.com/reference/kotlin/android/media/session/MediaController.TransportControls#play())can be called to start playback. If the preparation is not needed,[playFromSearch](https://developer.android.com/reference/kotlin/android/media/session/MediaController.TransportControls#playFromSearch(kotlin.String,%20android.os.Bundle))can be directly called without this method.

|                                                                           Parameters                                                                            ||
|----------|-------------------------------------------------------------------------------------------------------------------------------------------------------|
| `query`  | [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)!:The search query.                                                   |
| `extras` | [Bundle](https://developer.android.com/reference/kotlin/android/os/Bundle.html#)!:Optional extras that can include extra information about the query. |

### prepareFromUri

Added in[API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

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

Request that the player prepare playback for a specific[Uri](https://developer.android.com/reference/kotlin/android/net/Uri.html#). 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](https://developer.android.com/reference/kotlin/android/media/session/PlaybackState#STATE_PAUSED:kotlin.Int). Afterwards,[play](https://developer.android.com/reference/kotlin/android/media/session/MediaController.TransportControls#play())can be called to start playback. If the preparation is not needed,[playFromUri](https://developer.android.com/reference/kotlin/android/media/session/MediaController.TransportControls#playFromUri(android.net.Uri,%20android.os.Bundle))can be directly called without this method.

|                                                                                     Parameters                                                                                      ||
|----------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `uri`    | [Uri](https://developer.android.com/reference/kotlin/android/net/Uri.html#)!:The URI of the requested media.                                                              |
| `extras` | [Bundle](https://developer.android.com/reference/kotlin/android/os/Bundle.html#)!:Optional extras that can include extra information about the media item to be prepared. |

### rewind

Added in[API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
fun rewind(): Unit
```

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

### seekTo

Added in[API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
fun seekTo(pos: Long): Unit
```

Move to a new location in the media stream.

|                                                        Parameters                                                         ||
|-------|--------------------------------------------------------------------------------------------------------------------|
| `pos` | [Long](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html):Position to move to, in milliseconds. |

### sendCustomAction

Added in[API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
fun sendCustomAction(
    customAction: PlaybackState.CustomAction, 
    args: Bundle?
): Unit
```

Send a custom action back for the[MediaSession](https://developer.android.com/reference/kotlin/android/media/session/MediaSession)to perform.

|                                                                                                                                       Parameters                                                                                                                                       ||
|----------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `customAction` | [PlaybackState.CustomAction](https://developer.android.com/reference/kotlin/android/media/session/PlaybackState.CustomAction):The action to perform. This value cannot be`null`.                                                                                       |
| `args`         | [Bundle](https://developer.android.com/reference/kotlin/android/os/Bundle.html#)?:Optional arguments to supply to the[MediaSession](https://developer.android.com/reference/kotlin/android/media/session/MediaSession)for this custom action. This value may be`null`. |

### sendCustomAction

Added in[API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

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

Send the id and args from a custom action back for the[MediaSession](https://developer.android.com/reference/kotlin/android/media/session/MediaSession)to perform.

|                                                                                                                                                                                              Parameters                                                                                                                                                                                               ||
|----------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `action` | [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html):The action identifier of the[PlaybackState.CustomAction](https://developer.android.com/reference/kotlin/android/media/session/PlaybackState.CustomAction)as specified by the[MediaSession](https://developer.android.com/reference/kotlin/android/media/session/MediaSession). This value cannot be`null`. |
| `args`   | [Bundle](https://developer.android.com/reference/kotlin/android/os/Bundle.html#)?:Optional arguments to supply to the[MediaSession](https://developer.android.com/reference/kotlin/android/media/session/MediaSession)for this custom action. This value may be`null`.                                                                                                                      |

**See Also**

- [#sendCustomAction(PlaybackState.CustomAction action, Bundle args)](https://developer.android.com/reference/kotlin/android/media/session/MediaController.TransportControls#sendCustomAction(android.media.session.PlaybackState.CustomAction,%20android.os.Bundle))  

### setPlaybackSpeed

Added in[API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
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](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-float/index.html):The playback speed |

|                              Exceptions                              ||
|--------------------------------------|--------------------------------|
| `java.lang.IllegalArgumentException` | if the`speed`is equal to zero. |

### setRating

Added in[API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
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()](https://developer.android.com/reference/kotlin/android/media/session/MediaController#getRatingType()).

|                                                                Parameters                                                                ||
|----------|--------------------------------------------------------------------------------------------------------------------------------|
| `rating` | [Rating](https://developer.android.com/reference/kotlin/android/media/Rating.html#)!:The rating to set for the current content |

### skipToNext

Added in[API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
fun skipToNext(): Unit
```

Skip to the next item.  

### skipToPrevious

Added in[API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
fun skipToPrevious(): Unit
```

Skip to the previous item.  

### skipToQueueItem

Added in[API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
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](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
fun stop(): Unit
```

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