# MediaRouter.Callback

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

*** ** * ** ***


```
public abstract class MediaRouter.Callback
```

<br />

*** ** * ** ***

Interface for receiving events about media routing changes. All methods of this interface will be called from the application's main thread.

A Callback will only receive events relevant to routes that the callback was registered for unless the `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#CALLBACK_FLAG_UNFILTERED_EVENTS()` flag was specified in `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#addCallback(androidx.mediarouter.media.MediaRouteSelector,androidx.mediarouter.media.MediaRouter.Callback,int)`.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#addCallback(androidx.mediarouter.media.MediaRouteSelector,androidx.mediarouter.media.MediaRouter.Callback,int)` |   |
| `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#removeCallback(androidx.mediarouter.media.MediaRouter.Callback)` |   |

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.Callback#Callback()()` |

| ### Public methods |
|---|---|
| `void` | `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.Callback#onProviderAdded(androidx.mediarouter.media.MediaRouter,androidx.mediarouter.media.MediaRouter.ProviderInfo)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter router, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.ProviderInfo provider )` Called when a media route provider has been added. |
| `void` | `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.Callback#onProviderChanged(androidx.mediarouter.media.MediaRouter,androidx.mediarouter.media.MediaRouter.ProviderInfo)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter router, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.ProviderInfo provider )` Called when a property of the indicated media route provider has changed. |
| `void` | `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.Callback#onProviderRemoved(androidx.mediarouter.media.MediaRouter,androidx.mediarouter.media.MediaRouter.ProviderInfo)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter router, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.ProviderInfo provider )` Called when a media route provider has been removed. |
| `void` | `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.Callback#onRouteAdded(androidx.mediarouter.media.MediaRouter,androidx.mediarouter.media.MediaRouter.RouteInfo)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter router, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.RouteInfo route )` Called when a media route has been added. |
| `void` | `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.Callback#onRouteChanged(androidx.mediarouter.media.MediaRouter,androidx.mediarouter.media.MediaRouter.RouteInfo)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter router, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.RouteInfo route )` Called when a property of the indicated media route has changed. |
| `void` | `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.Callback#onRouteConnected(androidx.mediarouter.media.MediaRouter,androidx.mediarouter.media.MediaRouter.RouteInfo,androidx.mediarouter.media.MediaRouter.RouteInfo)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter router, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.RouteInfo connectedRoute, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.RouteInfo requestedRoute )` Called when the supplied media route becomes connected. |
| `void` | `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.Callback#onRouteDisconnected(androidx.mediarouter.media.MediaRouter,androidx.mediarouter.media.MediaRouter.RouteInfo,androidx.mediarouter.media.MediaRouter.RouteInfo,int)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter router, @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.RouteInfo disconnectedRoute, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.RouteInfo requestedRoute, int reason )` Called when the supplied media route becomes disconnected. |
| `void` | `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.Callback#onRoutePresentationDisplayChanged(androidx.mediarouter.media.MediaRouter,androidx.mediarouter.media.MediaRouter.RouteInfo)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter router, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.RouteInfo route )` Called when a media route's presentation display changes. |
| `void` | `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.Callback#onRouteRemoved(androidx.mediarouter.media.MediaRouter,androidx.mediarouter.media.MediaRouter.RouteInfo)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter router, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.RouteInfo route )` Called when a media route has been removed. |
| `void` | `[onRouteSelected](https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.Callback#onRouteSelected(androidx.mediarouter.media.MediaRouter,androidx.mediarouter.media.MediaRouter.RouteInfo))( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter router, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.RouteInfo route )` **This method is deprecated.** Use `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.Callback#onRouteSelected(androidx.mediarouter.media.MediaRouter,androidx.mediarouter.media.MediaRouter.RouteInfo,int)` instead. <br /> |
| `void` | `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.Callback#onRouteSelected(androidx.mediarouter.media.MediaRouter,androidx.mediarouter.media.MediaRouter.RouteInfo,int)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter router, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.RouteInfo route, int reason )` Called when the supplied media route becomes selected as the active route. |
| `void` | `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.Callback#onRouteSelected(androidx.mediarouter.media.MediaRouter,androidx.mediarouter.media.MediaRouter.RouteInfo,int,androidx.mediarouter.media.MediaRouter.RouteInfo)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter router, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.RouteInfo selectedRoute, int reason, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.RouteInfo requestedRoute )` Called when the supplied media route becomes selected as the active route, which may be different from the route requested by `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#selectRoute(androidx.mediarouter.media.MediaRouter.RouteInfo)`. |
| `void` | `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.Callback#onRouteSelected(androidx.mediarouter.media.MediaRouter,androidx.mediarouter.media.MediaRouter.RouteInfo,androidx.mediarouter.media.MediaRouter.RouteInfo,androidx.mediarouter.media.SelectionInfo)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter router, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.RouteInfo selectedRoute, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.RouteInfo requestedRoute, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/SelectionInfo selectionInfo )` Called when the selected route changes. |
| `void` | `[onRouteUnselected](https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.Callback#onRouteUnselected(androidx.mediarouter.media.MediaRouter,androidx.mediarouter.media.MediaRouter.RouteInfo))( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter router, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.RouteInfo route )` **This method is deprecated.** Use `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.Callback#onRouteUnselected(androidx.mediarouter.media.MediaRouter,androidx.mediarouter.media.MediaRouter.RouteInfo,int)` instead. <br /> |
| `void` | `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.Callback#onRouteUnselected(androidx.mediarouter.media.MediaRouter,androidx.mediarouter.media.MediaRouter.RouteInfo,int)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter router, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.RouteInfo route, int reason )` Called when the supplied media route becomes unselected as the active route. |
| `void` | `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.Callback#onRouteVolumeChanged(androidx.mediarouter.media.MediaRouter,androidx.mediarouter.media.MediaRouter.RouteInfo)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter router, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.RouteInfo route )` Called when a media route's volume changes. |

## Public constructors

### Callback

Added in 1.1.0

```
public Callback()
```

## Public methods

### onProviderAdded

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

```
public void onProviderAdded(
    @NonNull MediaRouter router,
    @NonNull MediaRouter.ProviderInfo provider
)
```

Called when a media route provider has been added.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter router` | The media router reporting the event. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.ProviderInfo provider` | The provider that has become available for use. |

### onProviderChanged

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

```
public void onProviderChanged(
    @NonNull MediaRouter router,
    @NonNull MediaRouter.ProviderInfo provider
)
```

Called when a property of the indicated media route provider has changed.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter router` | The media router reporting the event. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.ProviderInfo provider` | The provider that was changed. |

### onProviderRemoved

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

```
public void onProviderRemoved(
    @NonNull MediaRouter router,
    @NonNull MediaRouter.ProviderInfo provider
)
```

Called when a media route provider has been removed.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter router` | The media router reporting the event. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.ProviderInfo provider` | The provider that has been removed from availability. |

### onRouteAdded

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

```
public void onRouteAdded(
    @NonNull MediaRouter router,
    @NonNull MediaRouter.RouteInfo route
)
```

Called when a media route has been added.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter router` | The media router reporting the event. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.RouteInfo route` | The route that has become available for use. |

### onRouteChanged

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

```
public void onRouteChanged(
    @NonNull MediaRouter router,
    @NonNull MediaRouter.RouteInfo route
)
```

Called when a property of the indicated media route has changed.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter router` | The media router reporting the event. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.RouteInfo route` | The route that was changed. |

### onRouteConnected

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

```
public void onRouteConnected(
    @NonNull MediaRouter router,
    @NonNull MediaRouter.RouteInfo connectedRoute,
    @NonNull MediaRouter.RouteInfo requestedRoute
)
```

Called when the supplied media route becomes connected.

Route connection doesn't affect the selected route. Apps can keep their selected routes while connecting to other routes.

The connected route could be different from the route requested by `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.RouteInfo#connect()`. This can happen when the `https://developer.android.com/reference/androidx/mediarouter/media/MediaTransferReceiver` is enabled.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter router` | the media router reporting the event. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.RouteInfo connectedRoute` | the route that has been connected. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.RouteInfo requestedRoute` | the route that was requested to be connected. |

### onRouteDisconnected

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

```
public void onRouteDisconnected(
    @NonNull MediaRouter router,
    @Nullable MediaRouter.RouteInfo disconnectedRoute,
    @NonNull MediaRouter.RouteInfo requestedRoute,
    int reason
)
```

Called when the supplied media route becomes disconnected.

Route disconnection doesn't affect the selected route. Apps can keep their selected route while disconnecting other connected routes.

The disconnected route could be different from the route requested by `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.RouteInfo#connect()` or `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.RouteInfo#disconnect()`.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter router` | the media router reporting the event. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.RouteInfo disconnectedRoute` | the route that has been disconnected if the route has an established connection, or `null` if the connection hasn't been completed. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.RouteInfo requestedRoute` | the route that originated the connection request through `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.RouteInfo#connect()` or originated the disconnection request through `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.RouteInfo#disconnect()`. |
| `int reason` | the reason for disconnecting the route. |

### onRoutePresentationDisplayChanged

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

```
public void onRoutePresentationDisplayChanged(
    @NonNull MediaRouter router,
    @NonNull MediaRouter.RouteInfo route
)
```

Called when a media route's presentation display changes.

This method is called whenever the route's presentation display becomes available, is removed or has changes to some of its properties (such as its size).

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter router` | The media router reporting the event. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.RouteInfo route` | The route whose presentation display changed. |

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.RouteInfo#getPresentationDisplay()` |   |

### onRouteRemoved

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

```
public void onRouteRemoved(
    @NonNull MediaRouter router,
    @NonNull MediaRouter.RouteInfo route
)
```

Called when a media route has been removed.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter router` | The media router reporting the event. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.RouteInfo route` | The route that has been removed from availability. |

### onRouteSelected

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)

```
public void [onRouteSelected](https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.Callback#onRouteSelected(androidx.mediarouter.media.MediaRouter,androidx.mediarouter.media.MediaRouter.RouteInfo))(
    @NonNull MediaRouter router,
    @NonNull MediaRouter.RouteInfo route
)
```

> [!CAUTION]
> **This method is deprecated.**   
>
> Use `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.Callback#onRouteSelected(androidx.mediarouter.media.MediaRouter,androidx.mediarouter.media.MediaRouter.RouteInfo,int)` instead.

Called when the supplied media route becomes selected as the active route.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter router` | The media router reporting the event. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.RouteInfo route` | The route that has been selected. |

### onRouteSelected

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

```
public void onRouteSelected(
    @NonNull MediaRouter router,
    @NonNull MediaRouter.RouteInfo route,
    int reason
)
```

Called when the supplied media route becomes selected as the active route.

The reason provided will be one of the following:

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

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter router` | The media router reporting the event. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.RouteInfo route` | The route that has been selected. |
| `int reason` | The reason for unselecting the previous route. |

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.Callback#onRouteSelected(androidx.mediarouter.media.MediaRouter,androidx.mediarouter.media.MediaRouter.RouteInfo,androidx.mediarouter.media.MediaRouter.RouteInfo,androidx.mediarouter.media.SelectionInfo)` |   |

### onRouteSelected

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

```
public void onRouteSelected(
    @NonNull MediaRouter router,
    @NonNull MediaRouter.RouteInfo selectedRoute,
    int reason,
    @NonNull MediaRouter.RouteInfo requestedRoute
)
```

Called when the supplied media route becomes selected as the active route, which may be different from the route requested by `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#selectRoute(androidx.mediarouter.media.MediaRouter.RouteInfo)`. That can happen when `https://developer.android.com/reference/androidx/mediarouter/media/MediaTransferReceiver` is enabled. The default implementation calls `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.Callback#onRouteSelected(androidx.mediarouter.media.MediaRouter,androidx.mediarouter.media.MediaRouter.RouteInfo,int)` with the actually selected route.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter router` | The media router reporting the event. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.RouteInfo selectedRoute` | The route that has been selected. |
| `int reason` | The reason for unselecting the previous route. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.RouteInfo requestedRoute` | The route that was requested to be selected. |

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.Callback#onRouteSelected(androidx.mediarouter.media.MediaRouter,androidx.mediarouter.media.MediaRouter.RouteInfo,androidx.mediarouter.media.MediaRouter.RouteInfo,androidx.mediarouter.media.SelectionInfo)` |   |

### onRouteSelected

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

```
public void onRouteSelected(
    @NonNull MediaRouter router,
    @NonNull MediaRouter.RouteInfo selectedRoute,
    @NonNull MediaRouter.RouteInfo requestedRoute,
    @NonNull SelectionInfo selectionInfo
)
```

Called when the selected route changes.

The `selectedRoute` and the `requestedRoute` may be different. For example, when dynamic group route controlling is enabled (see `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouteProviderDescriptor#supportsDynamicGroupRoute()`). The requested route is the `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.RouteInfo` passed to `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#selectRoute(androidx.mediarouter.media.MediaRouter.RouteInfo)`. The selected route, on the other hand, represents the created dynamic group, whose composing routes are available via `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.GroupRouteInfo#getRoutesInGroup()`. This enables the client to add other routes (beyond the requested route) to the selected route group.

The selected route matches the requested route when dynamic groups are not `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouteProviderDescriptor#supportsDynamicGroupRoute()`.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter router` | The media router reporting the event. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.RouteInfo selectedRoute` | The selected route, which may differ from the requested route. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.RouteInfo requestedRoute` | The route that was requested to be selected (for example, using `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#selectRoute(androidx.mediarouter.media.MediaRouter.RouteInfo)`). |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/SelectionInfo selectionInfo` | Information about the route selection. |

### onRouteUnselected

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)

```
public void [onRouteUnselected](https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.Callback#onRouteUnselected(androidx.mediarouter.media.MediaRouter,androidx.mediarouter.media.MediaRouter.RouteInfo))(
    @NonNull MediaRouter router,
    @NonNull MediaRouter.RouteInfo route
)
```

> [!CAUTION]
> **This method is deprecated.**   
>
> Use `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.Callback#onRouteUnselected(androidx.mediarouter.media.MediaRouter,androidx.mediarouter.media.MediaRouter.RouteInfo,int)` instead.

Called when the supplied media route becomes unselected as the active route. For detailed reason, override `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.Callback#onRouteUnselected(androidx.mediarouter.media.MediaRouter,androidx.mediarouter.media.MediaRouter.RouteInfo,int)` instead.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter router` | The media router reporting the event. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.RouteInfo route` | The route that has been unselected. |

### onRouteUnselected

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

```
public void onRouteUnselected(
    @NonNull MediaRouter router,
    @NonNull MediaRouter.RouteInfo route,
    int reason
)
```

Called when the supplied media route becomes unselected as the active route. The default implementation calls `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.Callback#onRouteUnselected(androidx.mediarouter.media.MediaRouter,androidx.mediarouter.media.MediaRouter.RouteInfo)`.

The reason provided will be one of the following:

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

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter router` | The media router reporting the event. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.RouteInfo route` | The route that has been unselected. |
| `int reason` | The reason for unselecting the route. |

### onRouteVolumeChanged

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

```
public void onRouteVolumeChanged(
    @NonNull MediaRouter router,
    @NonNull MediaRouter.RouteInfo route
)
```

Called when a media route's volume changes.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter router` | The media router reporting the event. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.RouteInfo route` | The route whose volume changed. |