# MediaRouter.OnPrepareTransferListener

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.OnPrepareTransferListener) Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/mediarouter#1.2.0)

*** ** * ** ***


```
public interface MediaRouter.OnPrepareTransferListener
```

<br />

*** ** * ** ***

Listener for receiving events when the selected route is about to be changed.

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

## Summary

| ### Public methods |
|---|---|
| `abstract @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html<https://developer.android.com/reference/java/lang/Void.html>` | `@https://developer.android.com/reference/androidx/annotation/MainThread https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.OnPrepareTransferListener#onPrepareTransfer(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.RouteInfo fromRoute, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.RouteInfo toRoute )` Implement this to handle transfer seamlessly. |

## Public methods

### onPrepareTransfer

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

```
@MainThread
abstract @Nullable ListenableFuture<Void> onPrepareTransfer(
    @NonNull MediaRouter.RouteInfo fromRoute,
    @NonNull MediaRouter.RouteInfo toRoute
)
```

Implement this to handle transfer seamlessly.

Setting the listener will defer stopping the previous route, from which you may get the media status to resume media seamlessly on the new route. When the transfer is prepared, set the returned future to stop media being played on the previous route and release resources. This method is called on the main thread.

`https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.Callback#onRouteUnselected(androidx.mediarouter.media.MediaRouter,androidx.mediarouter.media.MediaRouter.RouteInfo,int)` and `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.Callback#onRouteSelected(androidx.mediarouter.media.MediaRouter,androidx.mediarouter.media.MediaRouter.RouteInfo,int)` are called after the future is done.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.RouteInfo fromRoute` | The route that is about to be unselected. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.RouteInfo toRoute` | The route that is about to be selected. |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html<https://developer.android.com/reference/java/lang/Void.html>` | A `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html` whose completion indicates that the transfer is prepared or `null` to indicate that no preparation is needed. If a future is returned, until the future is completed, the media continues to be played on the previous route. |