Google 致力于为黑人社区推动种族平等。查看具体举措

MediaRouter

class MediaRouter
kotlin.Any
   ↳ 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. 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
abstract

Interface for receiving events about media routing changes.

abstract

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

abstract

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

Provides information about a media route provider.

Provides information about a media route.

Constants
static Int

Flag for isRouteAvailable: Ignore the default route.

static Int

Flag for isRouteAvailable: Require an actual route to be matched.

static Int

Flag for #addCallback: Request passive route discovery while this callback is registered, even on low-RAM devices.

static Int

Flag for #addCallback: Actively scan for routes while this callback is registered.

static Int

Flag for #addCallback: Request passive route discovery while this callback is registered, except on low-RAM devices.

static Int

Flag for #addCallback: Do not filter route events.

static Int

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

static Int

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

static Int

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

static Int

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

Public methods
Unit

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

Unit
addCallback(@NonNull selector: MediaRouteSelector, @NonNull callback: MediaRouter.Callback, flags: Int)

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

Unit
addProvider(@NonNull providerInstance: MediaRouteProvider)

Registers a media route provider within this application process.

Unit
addRemoteControlClient(@NonNull remoteControlClient: Any)

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

MediaRouter.RouteInfo!

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

MediaRouter.RouteInfo

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

static MediaRouter!
getInstance(@NonNull context: Context)

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

MediaSessionCompat.Token!

MutableList<MediaRouter.ProviderInfo!>!

Gets information about the route providers currently known to this media router.

MediaRouterParams?

Gets parameters of the media router service associated with this media router.

MutableList<MediaRouter.RouteInfo!>!

Gets information about the routes currently known to this media router.

MediaRouter.RouteInfo

Gets the currently selected route.