Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Methods](https://developer.android.com/reference/android/media/MediaRouter2.RoutingController#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/android/media/MediaRouter2.RoutingController#inhmethods)

# MediaRouter2.RoutingController

*** ** * ** ***


`
public


class
MediaRouter2.RoutingController
`


`

extends https://developer.android.com/reference/java/lang/Object


`

`


`

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.media.MediaRouter2.RoutingController |

<br />

*** ** * ** ***

Controls a media routing session.

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

## Summary

| ### Public methods ||
|---|---|
| ` void` | ` https://developer.android.com/reference/android/media/MediaRouter2.RoutingController#deselectRoute(android.media.MediaRoute2Info)(https://developer.android.com/reference/android/media/MediaRoute2Info route) ` Deselects a route from the remote session. |
| ` https://developer.android.com/reference/android/os/Bundle` | ` https://developer.android.com/reference/android/media/MediaRouter2.RoutingController#getControlHints()() ` Gets the control hints used to control routing session if available. |
| ` https://developer.android.com/reference/java/util/List<https://developer.android.com/reference/android/media/MediaRoute2Info>` | ` https://developer.android.com/reference/android/media/MediaRouter2.RoutingController#getDeselectableRoutes()() ` Returns the unmodifiable list of deselectable routes for the session. |
| ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/android/media/MediaRouter2.RoutingController#getId()() ` |
| ` https://developer.android.com/reference/android/media/RoutingSessionInfo` | ` https://developer.android.com/reference/android/media/MediaRouter2.RoutingController#getRoutingSessionInfo()() ` Returns the current `https://developer.android.com/reference/android/media/RoutingSessionInfo` associated to this controller. |
| ` https://developer.android.com/reference/java/util/List<https://developer.android.com/reference/android/media/MediaRoute2Info>` | ` https://developer.android.com/reference/android/media/MediaRouter2.RoutingController#getSelectableRoutes()() ` Returns the unmodifiable list of selectable routes for the session. |
| ` https://developer.android.com/reference/java/util/List<https://developer.android.com/reference/android/media/MediaRoute2Info>` | ` https://developer.android.com/reference/android/media/MediaRouter2.RoutingController#getSelectedRoutes()() ` Returns the unmodifiable list of currently selected routes |
| ` https://developer.android.com/reference/java/util/List<https://developer.android.com/reference/android/media/MediaRoute2Info>` | ` https://developer.android.com/reference/android/media/MediaRouter2.RoutingController#getTransferableRoutes()() ` Returns the unmodifiable list of transferable routes for the session. |
| ` int` | ` https://developer.android.com/reference/android/media/MediaRouter2.RoutingController#getVolume()() ` Gets the current volume of the session. |
| ` int` | ` https://developer.android.com/reference/android/media/MediaRouter2.RoutingController#getVolumeHandling()() ` Gets the information about how volume is handled on the session. |
| ` int` | ` https://developer.android.com/reference/android/media/MediaRouter2.RoutingController#getVolumeMax()() ` Gets the maximum volume of the session. |
| ` boolean` | ` https://developer.android.com/reference/android/media/MediaRouter2.RoutingController#isReleased()() ` Returns true if this controller is released, false otherwise. |
| ` void` | ` https://developer.android.com/reference/android/media/MediaRouter2.RoutingController#release()() ` Releases this controller and the corresponding session. |
| ` void` | ` https://developer.android.com/reference/android/media/MediaRouter2.RoutingController#selectRoute(android.media.MediaRoute2Info)(https://developer.android.com/reference/android/media/MediaRoute2Info route) ` Selects a route for the remote session. |
| ` void` | ` https://developer.android.com/reference/android/media/MediaRouter2.RoutingController#setVolume(int)(int volume) ` Requests a volume change for the remote session asynchronously. |
| ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/android/media/MediaRouter2.RoutingController#toString()() ` Returns a string representation of the object. |
| ` boolean` | ` https://developer.android.com/reference/android/media/MediaRouter2.RoutingController#wasTransferInitiatedBySelf()() ` Returns whether the transfer was initiated by the calling app (as determined by comparing `https://developer.android.com/reference/android/os/UserHandle` and package name). |

| ### Inherited methods |
|---|---|
| From class ` https://developer.android.com/reference/java/lang/Object ` |---|---| | ` https://developer.android.com/reference/java/lang/Object` | ` https://developer.android.com/reference/java/lang/Object#clone()() ` Creates and returns a copy of this object. | | ` boolean` | ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) ` Indicates whether some other object is "equal to" this one. | | ` void` | ` https://developer.android.com/reference/java/lang/Object#finalize()() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. | | ` final https://developer.android.com/reference/java/lang/Class<?>` | ` https://developer.android.com/reference/java/lang/Object#getClass()() ` Returns the runtime class of this `Object`. | | ` int` | ` https://developer.android.com/reference/java/lang/Object#hashCode()() ` Returns a hash code value for the object. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#notify()() ` Wakes up a single thread that is waiting on this object's monitor. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#notifyAll()() ` Wakes up all threads that are waiting on this object's monitor. | | ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/java/lang/Object#toString()() ` Returns a string representation of the object. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos) ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis) ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait()() ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*. | ||

## Public methods

### deselectRoute

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

```
public void deselectRoute (MediaRoute2Info route)
```

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 `https://developer.android.com/reference/android/media/MediaRouter2.RoutingController#getSelectedRoutes()`
- It should be included in `https://developer.android.com/reference/android/media/MediaRouter2.RoutingController#getDeselectableRoutes()`

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

<br />

<br />

| Parameters ||
|---|---|
| `route` | `MediaRoute2Info`: This value cannot be `null`. <br /> |

**See also:**

- `https://developer.android.com/reference/android/media/MediaRouter2.RoutingController#getSelectedRoutes()`
- `https://developer.android.com/reference/android/media/MediaRouter2.RoutingController#getDeselectableRoutes()`
- `https://developer.android.com/reference/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#ApiLevels)

```
public Bundle getControlHints ()
```

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

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/os/Bundle` | This value may be `null`. <br /> |

### getDeselectableRoutes

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

```
public List<MediaRoute2Info> getDeselectableRoutes ()
```

Returns the unmodifiable list of deselectable routes for the session.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/List<https://developer.android.com/reference/android/media/MediaRoute2Info>` | This value cannot be `null`. <br /> |

**See also:**

- `https://developer.android.com/reference/android/media/RoutingSessionInfo#getDeselectableRoutes()`

### getId

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

```
public String getId ()
```

<br />

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | the ID of the controller. It is globally unique. This value cannot be `null`. <br /> |

### getRoutingSessionInfo

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

```
public RoutingSessionInfo getRoutingSessionInfo ()
```

Returns the current `https://developer.android.com/reference/android/media/RoutingSessionInfo` associated to this controller.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/media/RoutingSessionInfo` | This value cannot be `null`. <br /> |

### getSelectableRoutes

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

```
public List<MediaRoute2Info> getSelectableRoutes ()
```

Returns the unmodifiable list of selectable routes for the session.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/List<https://developer.android.com/reference/android/media/MediaRoute2Info>` | This value cannot be `null`. <br /> |

**See also:**

- `https://developer.android.com/reference/android/media/RoutingSessionInfo#getSelectableRoutes()`

### getSelectedRoutes

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

```
public List<MediaRoute2Info> getSelectedRoutes ()
```

Returns the unmodifiable list of currently selected routes

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/List<https://developer.android.com/reference/android/media/MediaRoute2Info>` | This value cannot be `null`. <br /> |

**See also:**

- `https://developer.android.com/reference/android/media/RoutingSessionInfo#getSelectedRoutes()`

### getTransferableRoutes

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

```
public List<MediaRoute2Info> getTransferableRoutes ()
```

Returns the unmodifiable list of transferable routes for the session.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/List<https://developer.android.com/reference/android/media/MediaRoute2Info>` | This value cannot be `null`. <br /> |

**See also:**

- `https://developer.android.com/reference/android/media/RoutingSessionInfo#getTransferableRoutes()`

### getVolume

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

```
public int getVolume ()
```

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 `https://developer.android.com/reference/android/media/MediaRoute2Info#getVolume()` to get the volume of a route,

<br />

| Returns ||
|---|---|
| `int` | <br /> |

**See also:**

- `https://developer.android.com/reference/android/media/MediaRoute2Info#getVolume()`

### getVolumeHandling

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

```
public int getVolumeHandling ()
```

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.

<br />

| Returns ||
|---|---|
| `int` | `https://developer.android.com/reference/android/media/MediaRoute2Info#PLAYBACK_VOLUME_FIXED` or `https://developer.android.com/reference/android/media/MediaRoute2Info#PLAYBACK_VOLUME_VARIABLE` Value is one of the following: - `https://developer.android.com/reference/android/media/MediaRoute2Info#PLAYBACK_VOLUME_FIXED` - `https://developer.android.com/reference/android/media/MediaRoute2Info#PLAYBACK_VOLUME_VARIABLE` |

### getVolumeMax

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

```
public int getVolumeMax ()
```

Gets the maximum volume of the session.

<br />

| Returns ||
|---|---|
| `int` | <br /> |

### isReleased

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

```
public boolean isReleased ()
```

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.

<br />

| Returns ||
|---|---|
| `boolean` | <br /> |

**See also:**

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

### release

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

```
public void release ()
```

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.

<br />

### selectRoute

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

```
public void selectRoute (MediaRoute2Info route)
```

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 `https://developer.android.com/reference/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 `https://developer.android.com/reference/android/media/MediaRouter2.RoutingController#getSelectedRoutes()`
- It should be included in `https://developer.android.com/reference/android/media/MediaRouter2.RoutingController#getSelectableRoutes()`

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

<br />

<br />

| Parameters ||
|---|---|
| `route` | `MediaRoute2Info`: This value cannot be `null`. <br /> |

**See also:**

- `https://developer.android.com/reference/android/media/MediaRouter2.RoutingController#deselectRoute(android.media.MediaRoute2Info)`
- `https://developer.android.com/reference/android/media/MediaRouter2.RoutingController#getSelectedRoutes()`
- `https://developer.android.com/reference/android/media/MediaRouter2.RoutingController#getSelectableRoutes()`
- `https://developer.android.com/reference/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#ApiLevels)

```
public void setVolume (int volume)
```

Requests a volume change for the remote session asynchronously.

<br />

| Parameters ||
|---|---|
| `volume` | `int`: The new volume value between 0 and `https://developer.android.com/reference/android/media/MediaRouter2.RoutingController#getVolumeMax()` (inclusive). <br /> |

**See also:**

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

### toString

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

```
public String toString ()
```

Returns a string representation of the object.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | a string representation of the object. <br /> |

### wasTransferInitiatedBySelf

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

```
public boolean wasTransferInitiatedBySelf ()
```

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

<br />

| Returns ||
|---|---|
| `boolean` | <br /> |