MediaRouter

public final class MediaRouter
extends Object

java.lang.Object
   ↳ androidx.mediarouter.media.MediaRouter


MediaRouter allows applications to control the routing of media channels and streams from the current device to external speakers and destination devices.

A MediaRouter instance is retrieved through getInstance(Context). Applications can query the media router about the currently selected route and its capabilities to determine how to send content to the route's destination. Applications can also send control requests to the route to ask the route's destination to perform certain remote control functions such as playing media.

See also MediaRouteProvider for information on how an application can publish new media routes to the media router.

The media router API is not thread-safe; all interactions with it must be done from the main thread of the process.

Summary

Nested classes

class MediaRouter.Callback

Interface for receiving events about media routing changes. 

class MediaRouter.ControlRequestCallback

Callback which is invoked with the result of a media control request. 

interface MediaRouter.OnPrepareTransferListener

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

class MediaRouter.ProviderInfo

Provides information about a media route provider. 

class MediaRouter.RouteInfo

Provides information about a media route. 

Constants

int AVAILABILITY_FLAG_IGNORE_DEFAULT_ROUTE

Flag for isRouteAvailable(MediaRouteSelector, int): Ignore the default route.

int AVAILABILITY_FLAG_REQUIRE_MATCH

Flag for isRouteAvailable(MediaRouteSelector, int): Require an actual route to be matched.

int CALLBACK_FLAG_FORCE_DISCOVERY

Flag for addCallback(MediaRouteSelector, MediaRouter.Callback): Request passive route discovery while this callback is registered, even on low-RAM devices.

int CALLBACK_FLAG_PERFORM_ACTIVE_SCAN

Flag for addCallback(MediaRouteSelector, MediaRouter.Callback): Actively scan for routes while this callback is registered.

int CALLBACK_FLAG_REQUEST_DISCOVERY

Flag for addCallback(MediaRouteSelector, MediaRouter.Callback): Request passive route discovery while this callback is registered, except on low-RAM devices.

int CALLBACK_FLAG_UNFILTERED_EVENTS

Flag for addCallback(MediaRouteSelector, MediaRouter.Callback): Do not filter route events.

int UNSELECT_REASON_DISCONNECTED

Passed to MediaRouteProvider.RouteController.onUnselect(int), MediaRouter.Callback.onRouteUnselected(MediaRouter, RouteInfo, int) and MediaRouter.Callback.onRouteSelected(MediaRouter, RouteInfo, int) when the user pressed the disconnect button to disconnect and keep playing.

int UNSELECT_REASON_ROUTE_CHANGED

Passed to MediaRouteProvider.RouteController.onUnselect(int), MediaRouter.Callback.onRouteUnselected(MediaRouter, RouteInfo, int) and MediaRouter.Callback.onRouteSelected(MediaRouter, RouteInfo, int) when the user selected a different route.

int UNSELECT_REASON_STOPPED

Passed to MediaRouteProvider.RouteController.onUnselect(int), MediaRouter.Callback.onRouteUnselected(MediaRouter, RouteInfo, int) and MediaRouter.Callback.onRouteSelected(MediaRouter, RouteInfo, int) when the user pressed the stop casting button.

int UNSELECT_REASON_UNKNOWN

Passed to MediaRouteProvider.RouteController.onUnselect(int), MediaRouter.Callback.onRouteUnselected(MediaRouter, RouteInfo, int) and MediaRouter.Callback.onRouteSelected(MediaRouter, RouteInfo, int) when the reason the route was unselected is unknown.

Public methods

void addCallback(MediaRouteSelector selector, MediaRouter.Callback callback)

Registers a callback to discover routes that match the selector and to receive events when they change.

void addCallback(MediaRouteSelector selector, MediaRouter.Callback callback, int flags)

Registers a callback to discover routes that match the selector and to receive events when they change.

void addProvider(MediaRouteProvider providerInstance)

Registers a media route provider within this application process.

void addRemoteControlClient(Object remoteControlClient)

Adds a remote control client to enable remote control of the volume of the selected route.

MediaRouter.RouteInfo getBluetoothRoute()

Gets a bluetooth route for playing media content on the system.

MediaRouter.RouteInfo getDefaultRoute()

Gets the default route for playing media content on the system.

static MediaRouter getInstance(Context context)

Gets an instance of the media router service associated with the context.

MediaSessionCompat.Token getMediaSessionToken()
List<MediaRouter.ProviderInfo>