# MediaRouter2.RoutingController

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

# RoutingController

*** ** * ** ***

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

```
class RoutingController
```

|---|----------------------------------------------------------------------------------------------------------------------------------------------|
| [kotlin.Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)                                                               ||
| ↳ | [android.media.MediaRouter2.RoutingController](https://developer.android.com/reference/kotlin/android/media/MediaRouter2.RoutingController#) |

Controls a media routing session.

Routing controllers wrap a[RoutingSessionInfo](https://developer.android.com/reference/kotlin/android/media/RoutingSessionInfo), taking care of mapping route ids to[MediaRoute2Info](https://developer.android.com/reference/kotlin/android/media/MediaRoute2Info)instances. You can still access the underlying session using[getRoutingSessionInfo()](https://developer.android.com/reference/kotlin/android/media/MediaRouter2.RoutingController#getRoutingSessionInfo()), but keep in mind it can be changed by other threads. Changes to the routing session are notified via[ControllerCallback](https://developer.android.com/reference/kotlin/android/media/MediaRouter2.ControllerCallback).

## Summary

|                                                                                                                                                                                                                                                                                 Public methods                                                                                                                                                                                                                                                                                  ||
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| open[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)                                                                                                                                | [deselectRoute](https://developer.android.com/reference/kotlin/android/media/MediaRouter2.RoutingController#deselectRoute(android.media.MediaRoute2Info))`(`route:` `[MediaRoute2Info](https://developer.android.com/reference/kotlin/android/media/MediaRoute2Info)`)` Deselects a route from the remote session.                                             |
| open[Bundle](https://developer.android.com/reference/kotlin/android/os/Bundle.html#)?                                                                                                                           | [getControlHints](https://developer.android.com/reference/kotlin/android/media/MediaRouter2.RoutingController#getControlHints())`()` Gets the control hints used to control routing session if available.                                                                                                                                                      |
| open[MutableList](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-mutable-list/index.html)\<[MediaRoute2Info](https://developer.android.com/reference/kotlin/android/media/MediaRoute2Info)!\> | [getDeselectableRoutes](https://developer.android.com/reference/kotlin/android/media/MediaRouter2.RoutingController#getDeselectableRoutes())`()` Returns the unmodifiable list of deselectable routes for the session.                                                                                                                                         |
| open[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)                                                                                                                            | [getId](https://developer.android.com/reference/kotlin/android/media/MediaRouter2.RoutingController#getId())`()` <br />                                                                                                                                                                                                                                        |
| open[RoutingSessionInfo](https://developer.android.com/reference/kotlin/android/media/RoutingSessionInfo)                                                                                                       | [getRoutingSessionInfo](https://developer.android.com/reference/kotlin/android/media/MediaRouter2.RoutingController#getRoutingSessionInfo())`()` Returns the current[RoutingSessionInfo](https://developer.android.com/reference/kotlin/android/media/RoutingSessionInfo)associated to this controller.                                                        |
| open[MutableList](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-mutable-list/index.html)\<[MediaRoute2Info](https://developer.android.com/reference/kotlin/android/media/MediaRoute2Info)!\> | [getSelectableRoutes](https://developer.android.com/reference/kotlin/android/media/MediaRouter2.RoutingController#getSelectableRoutes())`()` Returns the unmodifiable list of selectable routes for the session.                                                                                                                                               |
| open[MutableList](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-mutable-list/index.html)\<[MediaRoute2Info](https://developer.android.com/reference/kotlin/android/media/MediaRoute2Info)!\> | [getSelectedRoutes](https://developer.android.com/reference/kotlin/android/media/MediaRouter2.RoutingController#getSelectedRoutes())`()` Returns the unmodifiable list of currently selected routes                                                                                                                                                            |
| open[MutableList](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-mutable-list/index.html)\<[MediaRoute2Info](https://developer.android.com/reference/kotlin/android/media/MediaRoute2Info)!\> | [getTransferableRoutes](https://developer.android.com/reference/kotlin/android/media/MediaRouter2.RoutingController#getTransferableRoutes())`()` Returns the unmodifiable list of transferable routes for the session.                                                                                                                                         |
| open[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)                                                                                                                                  | [getVolume](https://developer.android.com/reference/kotlin/android/media/MediaRouter2.RoutingController#getVolume())`()` Gets the current volume of the session.                                                                                                                                                                                               |
| open[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)                                                                                                                                  | [getVolumeHandling](https://developer.android.com/reference/kotlin/android/media/MediaRouter2.RoutingController#getVolumeHandling())`()` Gets the information about how volume is handled on the session.                                                                                                                                                      |
| open[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)                                                                                                                                  | [getVolumeMax](https://developer.android.com/reference/kotlin/android/media/MediaRouter2.RoutingController#getVolumeMax())`()` Gets the maximum volume of the session.                                                                                                                                                                                         |
| open[Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)                                                                                                                          | [isReleased](https://developer.android.com/reference/kotlin/android/media/MediaRouter2.RoutingController#isReleased())`()` Returns true if this controller is released, false otherwise.                                                                                                                                                                       |
| open[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)                                                                                                                                | [release](https://developer.android.com/reference/kotlin/android/media/MediaRouter2.RoutingController#release())`()` Releases this controller and the corresponding session.                                                                                                                                                                                   |
| open[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)                                                                                                                                | [selectRoute](https://developer.android.com/reference/kotlin/android/media/MediaRouter2.RoutingController#selectRoute(android.media.MediaRoute2Info))`(`route:` `[MediaRoute2Info](https://developer.android.com/reference/kotlin/android/media/MediaRoute2Info)`)` Selects a route for the remote session.                                                    |
| open[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)                                                                                                                                | [setVolume](https://developer.android.com/reference/kotlin/android/media/MediaRouter2.RoutingController#setVolume(kotlin.Int))`(`volume:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`)` Requests a volume change for the remote session asynchronously.                                                                       |
| open[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)                                                                                                                            | [toString](https://developer.android.com/reference/kotlin/android/media/MediaRouter2.RoutingController#toString())`()` <br />                                                                                                                                                                                                                                  |
| open[Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)                                                                                                                          | [wasTransferInitiatedBySelf](https://developer.android.com/reference/kotlin/android/media/MediaRouter2.RoutingController#wasTransferInitiatedBySelf())`()` Returns whether the transfer was initiated by the calling app (as determined by comparing[UserHandle](https://developer.android.com/reference/kotlin/android/os/UserHandle.html#)and package name). |

## Public methods

### deselectRoute

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

```
open fun deselectRoute(route: MediaRoute2Info): Unit
```

Deselects a route from the remote session. After a route is deselected, the media is expected to be stopped on the deselected route.

The given route must satisfy all of the following conditions:

- It should be included in[getSelectedRoutes()](https://developer.android.com/reference/kotlin/android/media/MediaRouter2.RoutingController#getSelectedRoutes())
- It should be included in[getDeselectableRoutes()](https://developer.android.com/reference/kotlin/android/media/MediaRouter2.RoutingController#getDeselectableRoutes())

If the route doesn't meet any of above conditions, it will be ignored.

|                                                              Parameters                                                              ||
|---------|-----------------------------------------------------------------------------------------------------------------------------|
| `route` | [MediaRoute2Info](https://developer.android.com/reference/kotlin/android/media/MediaRoute2Info):This value cannot be`null`. |

**See Also**

- <https://developer.android.com/reference/kotlin/android/media/MediaRouter2.RoutingController#getSelectedRoutes()>
- <https://developer.android.com/reference/kotlin/android/media/MediaRouter2.RoutingController#getDeselectableRoutes()>
- [ControllerCallback#onControllerUpdated](https://developer.android.com/reference/kotlin/android/media/MediaRouter2.ControllerCallback#onControllerUpdated(android.media.MediaRouter2.RoutingController))  

### getControlHints

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

```
open fun getControlHints(): Bundle?
```

Gets the control hints used to control routing session if available. It is set by the media route provider.

|                                                   Return                                                    ||
|-----------------------------------------------------------------------------------|--------------------------|
| [Bundle](https://developer.android.com/reference/kotlin/android/os/Bundle.html#)? | This value may be`null`. |

### getDeselectableRoutes

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

```
open fun getDeselectableRoutes(): MutableList<MediaRoute2Info!>
```

Returns the unmodifiable list of deselectable routes for the session.

|                                                                                                                 Return                                                                                                                 ||
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------|
| [MutableList](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-mutable-list/index.html)<[MediaRoute2Info](https://developer.android.com/reference/kotlin/android/media/MediaRoute2Info)!> | This value cannot be`null`. |

**See Also**

- [android.media.RoutingSessionInfo#getDeselectableRoutes()](https://developer.android.com/reference/kotlin/android/media/RoutingSessionInfo#getDeselectableRoutes())  

### getId

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

```
open fun getId(): String
```

|                                                                             Return                                                                             ||
|----------------------------------------------------------------------------------|------------------------------------------------------------------------------|
| [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html) | the ID of the controller. It is globally unique. This value cannot be`null`. |

### getRoutingSessionInfo

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

```
open fun getRoutingSessionInfo(): RoutingSessionInfo
```

Returns the current[RoutingSessionInfo](https://developer.android.com/reference/kotlin/android/media/RoutingSessionInfo)associated to this controller.

|                                                               Return                                                               ||
|-------------------------------------------------------------------------------------------------------|-----------------------------|
| [RoutingSessionInfo](https://developer.android.com/reference/kotlin/android/media/RoutingSessionInfo) | This value cannot be`null`. |

### getSelectableRoutes

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

```
open fun getSelectableRoutes(): MutableList<MediaRoute2Info!>
```

Returns the unmodifiable list of selectable routes for the session.

|                                                                                                                 Return                                                                                                                 ||
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------|
| [MutableList](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-mutable-list/index.html)<[MediaRoute2Info](https://developer.android.com/reference/kotlin/android/media/MediaRoute2Info)!> | This value cannot be`null`. |

**See Also**

- [android.media.RoutingSessionInfo#getSelectableRoutes()](https://developer.android.com/reference/kotlin/android/media/RoutingSessionInfo#getSelectableRoutes())  

### getSelectedRoutes

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

```
open fun getSelectedRoutes(): MutableList<MediaRoute2Info!>
```

Returns the unmodifiable list of currently selected routes

|                                                                                                                 Return                                                                                                                 ||
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------|
| [MutableList](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-mutable-list/index.html)<[MediaRoute2Info](https://developer.android.com/reference/kotlin/android/media/MediaRoute2Info)!> | This value cannot be`null`. |

**See Also**

- [android.media.RoutingSessionInfo#getSelectedRoutes()](https://developer.android.com/reference/kotlin/android/media/RoutingSessionInfo#getSelectedRoutes())  

### getTransferableRoutes

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

```
open fun getTransferableRoutes(): MutableList<MediaRoute2Info!>
```

Returns the unmodifiable list of transferable routes for the session.

|                                                                                                                 Return                                                                                                                 ||
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------|
| [MutableList](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-mutable-list/index.html)<[MediaRoute2Info](https://developer.android.com/reference/kotlin/android/media/MediaRoute2Info)!> | This value cannot be`null`. |

**See Also**

- [android.media.RoutingSessionInfo#getTransferableRoutes()](https://developer.android.com/reference/kotlin/android/media/RoutingSessionInfo#getTransferableRoutes())  

### getVolume

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

```
open fun getVolume(): Int
```

Gets the current volume of the session.

When it's available, it represents the volume of routing session, which is a group of selected routes. Use[MediaRoute2Info.getVolume()](https://developer.android.com/reference/kotlin/android/media/MediaRoute2Info#getVolume())to get the volume of a route,  
**See Also**

- [android.media.MediaRoute2Info#getVolume()](https://developer.android.com/reference/kotlin/android/media/MediaRoute2Info#getVolume())  

### getVolumeHandling

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

```
open fun getVolumeHandling(): Int
```

Gets the information about how volume is handled on the session.

Please note that you may not control the volume of the session even when you can control the volume of each selected route in the session.

|                                                                                                                                                                                                                                                                                                                                                                                  Return                                                                                                                                                                                                                                                                                                                                                                                  ||
|----------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html) | [MediaRoute2Info.PLAYBACK_VOLUME_FIXED](https://developer.android.com/reference/kotlin/android/media/MediaRoute2Info#PLAYBACK_VOLUME_FIXED:kotlin.Int)or[android.media.MediaRoute2Info#PLAYBACK_VOLUME_VARIABLE](https://developer.android.com/reference/kotlin/android/media/MediaRoute2Info#PLAYBACK_VOLUME_VARIABLE:kotlin.Int)Value is[android.media.MediaRoute2Info#PLAYBACK_VOLUME_FIXED](https://developer.android.com/reference/kotlin/android/media/MediaRoute2Info#PLAYBACK_VOLUME_FIXED:kotlin.Int), or[android.media.MediaRoute2Info#PLAYBACK_VOLUME_VARIABLE](https://developer.android.com/reference/kotlin/android/media/MediaRoute2Info#PLAYBACK_VOLUME_VARIABLE:kotlin.Int) |

### getVolumeMax

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

```
open fun getVolumeMax(): Int
```

Gets the maximum volume of the session.  

### isReleased

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

```
open fun isReleased(): Boolean
```

Returns true if this controller is released, false otherwise. If it is released, then all other getters from this instance may return invalid values. Also, any operations to this instance will be ignored once released.  
**See Also**

- [#release](https://developer.android.com/reference/kotlin/android/media/MediaRouter2.RoutingController#release())  

### release

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

```
open fun release(): Unit
```

Releases this controller and the corresponding session. Any operations on this controller after calling this method will be ignored. The devices that are playing media will stop playing it.  

### selectRoute

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

```
open fun selectRoute(route: MediaRoute2Info): Unit
```

Selects a route for the remote session. After a route is selected, the media is expected to be played to the all the selected routes. This is different from[transferring to a route](https://developer.android.com/reference/kotlin/android/media/MediaRouter2#transferTo(android.media.MediaRoute2Info)), where the media is expected to 'move' from one route to another.

The given route must satisfy all of the following conditions:

- It should not be included in[getSelectedRoutes()](https://developer.android.com/reference/kotlin/android/media/MediaRouter2.RoutingController#getSelectedRoutes())
- It should be included in[getSelectableRoutes()](https://developer.android.com/reference/kotlin/android/media/MediaRouter2.RoutingController#getSelectableRoutes())

If the route doesn't meet any of above conditions, it will be ignored.

|                                                              Parameters                                                              ||
|---------|-----------------------------------------------------------------------------------------------------------------------------|
| `route` | [MediaRoute2Info](https://developer.android.com/reference/kotlin/android/media/MediaRoute2Info):This value cannot be`null`. |

**See Also**

- [#deselectRoute(MediaRoute2Info)](https://developer.android.com/reference/kotlin/android/media/MediaRouter2.RoutingController#deselectRoute(android.media.MediaRoute2Info))
- <https://developer.android.com/reference/kotlin/android/media/MediaRouter2.RoutingController#getSelectedRoutes()>
- <https://developer.android.com/reference/kotlin/android/media/MediaRouter2.RoutingController#getSelectableRoutes()>
- [ControllerCallback#onControllerUpdated](https://developer.android.com/reference/kotlin/android/media/MediaRouter2.ControllerCallback#onControllerUpdated(android.media.MediaRouter2.RoutingController))  

### setVolume

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

```
open fun setVolume(volume: Int): Unit
```

Requests a volume change for the remote session asynchronously.

|                                                                                                                                   Parameters                                                                                                                                    ||
|----------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `volume` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html):The new volume value between 0 and[RoutingController.getVolumeMax](https://developer.android.com/reference/kotlin/android/media/MediaRouter2.RoutingController#getVolumeMax())(inclusive). |

**See Also**

- <https://developer.android.com/reference/kotlin/android/media/MediaRouter2.RoutingController#getVolume()>  

### toString

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

```
open fun toString(): String
```

|                                                          Return                                                          ||
|----------------------------------------------------------------------------------|----------------------------------------|
| [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html) | a string representation of the object. |

### wasTransferInitiatedBySelf

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

```
open fun wasTransferInitiatedBySelf(): Boolean
```

Returns whether the transfer was initiated by the calling app (as determined by comparing[UserHandle](https://developer.android.com/reference/kotlin/android/os/UserHandle.html#)and package name).