# MediaRouteProvider.RouteController

# MediaRouteProvider.RouteController

Artifact:[androidx.mediarouter:mediarouter](https://developer.android.com/jetpack/androidx/releases/mediarouter)  
[View Source](https://cs.android.com/search?q=file:androidx/mediarouter/media/MediaRouteProvider.java+class:androidx.mediarouter.media.MediaRouteProvider.RouteController)  
Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/mediarouter#1.1.0)

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/mediarouter/media/MediaRouteProvider.RouteController "View this page in Java")

<br />

```
abstract class MediaRouteProvider.RouteController
```

<br />

Known direct subclasses  
[MediaRouteProvider.DynamicGroupRouteController](https://developer.android.com/reference/kotlin/androidx/mediarouter/media/MediaRouteProvider.DynamicGroupRouteController)  

|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------|
| [MediaRouteProvider.DynamicGroupRouteController](https://developer.android.com/reference/kotlin/androidx/mediarouter/media/MediaRouteProvider.DynamicGroupRouteController) | Provides control over a dynamic group route. |

*** ** * ** ***

Provides control over a particular route.

The media router obtains a route controller for a route whenever it needs to control a route. When a route is selected, the media router invokes the[onSelect](https://developer.android.com/reference/kotlin/androidx/mediarouter/media/MediaRouteProvider.RouteController#onSelect())method of its route controller. While selected, the media router may call other methods of the route controller to request that it perform certain actions to the route. When a route is unselected, the media router invokes the[onUnselect](https://developer.android.com/reference/kotlin/androidx/mediarouter/media/MediaRouteProvider.RouteController#onUnselect(int))method of its route controller. When the media route no longer needs the route controller it will invoke the[onRelease](https://developer.android.com/reference/kotlin/androidx/mediarouter/media/MediaRouteProvider.RouteController#onRelease())method to allow the route controller to free its resources.

There may be multiple route controllers simultaneously active for the same route. Each route controller will be released separately.

All operations on the route controller are asynchronous and results are communicated via callbacks.

## Summary

|                                                                ### Public constructors                                                                |
|-------------------------------------------------------------------------------------------------------------------------------------------------------|
| [RouteController](https://developer.android.com/reference/kotlin/androidx/mediarouter/media/MediaRouteProvider.RouteController#RouteController())`()` |

|                                ### Public functions                                 |
|-------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | [onControlRequest](https://developer.android.com/reference/kotlin/androidx/mediarouter/media/MediaRouteProvider.RouteController#onControlRequest(android.content.Intent,androidx.mediarouter.media.MediaRouter.ControlRequestCallback))`(` ` intent: `[Intent](https://developer.android.com/reference/android/content/Intent.html)`,` ` callback: `[MediaRouter.ControlRequestCallback](https://developer.android.com/reference/kotlin/androidx/mediarouter/media/MediaRouter.ControlRequestCallback)`?` `)` Performs a[media control](https://developer.android.com/reference/kotlin/androidx/mediarouter/media/MediaControlIntent)request asynchronously on behalf of the route. |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)       | [onRelease](https://developer.android.com/reference/kotlin/androidx/mediarouter/media/MediaRouteProvider.RouteController#onRelease())`()` Releases the route controller, allowing it to free its resources.                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)       | [onSelect](https://developer.android.com/reference/kotlin/androidx/mediarouter/media/MediaRouteProvider.RouteController#onSelect())`()` Selects the route.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)       | [onSetVolume](https://developer.android.com/reference/kotlin/androidx/mediarouter/media/MediaRouteProvider.RouteController#onSetVolume(int))`(volume: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)` Requests to set the volume of the route.                                                                                                                                                                                                                                                                                                                                                                                                      |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)       | ~~[onUnselect](https://developer.android.com/reference/kotlin/androidx/mediarouter/media/MediaRouteProvider.RouteController#onUnselect())~~`()` **This function is deprecated.** Use[onUnselect](https://developer.android.com/reference/kotlin/androidx/mediarouter/media/MediaRouteProvider.RouteController#onUnselect(int))instead. <br />                                                                                                                                                                                                                                                                                                                                       |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)       | [onUnselect](https://developer.android.com/reference/kotlin/androidx/mediarouter/media/MediaRouteProvider.RouteController#onUnselect(int))`(reason: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)` Unselects the route and provides a reason.                                                                                                                                                                                                                                                                                                                                                                                                      |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)       | [onUpdateVolume](https://developer.android.com/reference/kotlin/androidx/mediarouter/media/MediaRouteProvider.RouteController#onUpdateVolume(int))`(delta: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)` Requests an incremental volume update for the route.                                                                                                                                                                                                                                                                                                                                                                                     |

## Public constructors

### RouteController

Added in 1.1.0  

```
RouteController()
```  

## Public functions

### onControlRequest

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/mediarouter#1.1.0)  

```
fun onControlRequest(
    intent: Intent,
    callback: MediaRouter.ControlRequestCallback?
): Boolean
```

Performs a[media control](https://developer.android.com/reference/kotlin/androidx/mediarouter/media/MediaControlIntent)request asynchronously on behalf of the route.  

|                                                                            Parameters                                                                             |
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `intent: `[Intent](https://developer.android.com/reference/android/content/Intent.html)                                                                           | A[media control intent](https://developer.android.com/reference/kotlin/androidx/mediarouter/media/MediaControlIntent).                                                                                             |
| `callback: `[MediaRouter.ControlRequestCallback](https://developer.android.com/reference/kotlin/androidx/mediarouter/media/MediaRouter.ControlRequestCallback)`?` | A[ControlRequestCallback](https://developer.android.com/reference/kotlin/androidx/mediarouter/media/MediaRouter.ControlRequestCallback)to invoke with the result of the request, or null if no result is required. |

|                                       Returns                                       |
|-------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | True if the controller intends to handle the request and will invoke the callback when finished. False if the controller will not handle the request and will not invoke the callback. |

|                                                      See also                                                      |
|--------------------------------------------------------------------------------------------------------------------|---|
| [MediaControlIntent](https://developer.android.com/reference/kotlin/androidx/mediarouter/media/MediaControlIntent) |   |

### onRelease

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/mediarouter#1.1.0)  

```
fun onRelease(): Unit
```

Releases the route controller, allowing it to free its resources.  

### onSelect

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/mediarouter#1.1.0)  

```
fun onSelect(): Unit
```

Selects the route.  

### onSetVolume

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/mediarouter#1.1.0)  

```
fun onSetVolume(volume: Int): Unit
```

Requests to set the volume of the route.  

|                                      Parameters                                       |
|---------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `volume: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | The new volume value between 0 and[getVolumeMax](https://developer.android.com/reference/kotlin/androidx/mediarouter/media/MediaRouteDescriptor#getVolumeMax()). |

### onUnselect

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/mediarouter#1.1.0)  
Deprecated in[1.2.0](https://developer.android.com/jetpack/androidx/releases/mediarouter#1.2.0)  

```
fun [onUnselect](https://developer.android.com/reference/kotlin/androidx/mediarouter/media/MediaRouteProvider.RouteController#onUnselect())(): Unit
```
| **This function is deprecated.**   
|
| Use[onUnselect](https://developer.android.com/reference/kotlin/androidx/mediarouter/media/MediaRouteProvider.RouteController#onUnselect(int))instead.

Unselects the route.  

### onUnselect

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/mediarouter#1.1.0)  

```
fun onUnselect(reason: Int): Unit
```

Unselects the route and provides a reason. The default implementation calls[onUnselect](https://developer.android.com/reference/kotlin/androidx/mediarouter/media/MediaRouteProvider.RouteController#onUnselect()).

The reason provided will be one of the following:

- [UNSELECT_REASON_UNKNOWN](https://developer.android.com/reference/kotlin/androidx/mediarouter/media/MediaRouter#UNSELECT_REASON_UNKNOWN())
- [UNSELECT_REASON_DISCONNECTED](https://developer.android.com/reference/kotlin/androidx/mediarouter/media/MediaRouter#UNSELECT_REASON_DISCONNECTED())
- [UNSELECT_REASON_STOPPED](https://developer.android.com/reference/kotlin/androidx/mediarouter/media/MediaRouter#UNSELECT_REASON_STOPPED())
- [UNSELECT_REASON_ROUTE_CHANGED](https://developer.android.com/reference/kotlin/androidx/mediarouter/media/MediaRouter#UNSELECT_REASON_ROUTE_CHANGED())

|                                      Parameters                                       |
|---------------------------------------------------------------------------------------|---------------------------------------|
| `reason: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | The reason for unselecting the route. |

### onUpdateVolume

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/mediarouter#1.1.0)  

```
fun onUpdateVolume(delta: Int): Unit
```

Requests an incremental volume update for the route.  

|                                      Parameters                                      |
|--------------------------------------------------------------------------------------|-----------------------------------------|
| `delta: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | The delta to add to the current volume. |