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 |
static Int |
Flag for |
static Int |
Flag for #addCallback: Request passive route discovery while this callback is registered, even on |
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 |
static Int |
Flag for #addCallback: Do not filter route events. |
static Int |
Passed to |
static Int |
Passed to |
static Int |
Passed to |
static Int |
Passed to |
Public methods | |
---|---|
Unit |
addCallback(selector: MediaRouteSelector!, callback: MediaRouter.Callback!) 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 |
MediaRouterParams? |
Gets |
MutableList<MediaRouter.RouteInfo!>! |
Gets information about the |
MediaRouter.RouteInfo |
Gets the currently selected route. |
Boolean |
isRouteAvailable(@NonNull selector: MediaRouteSelector, flags: Int) Returns true if there is a route that matches the specified selector. |
Unit |
removeCallback(@NonNull callback: MediaRouter.Callback) Removes the specified callback. |
Unit |
removeProvider(@NonNull providerInstance: MediaRouteProvider) Unregisters a media route provider within this application process. |
Unit |
removeRemoteControlClient(@NonNull remoteControlClient: Any) Removes a remote control client. |
Unit |
selectRoute(@NonNull route: MediaRouter.RouteInfo) Selects the specified route. |
Unit |
setMediaSession(mediaSession: Any!) Sets the media session to enable remote control of the volume of the selected route. |
Unit |
setMediaSessionCompat(mediaSession: MediaSessionCompat!) Sets a compat media session to enable remote control of the volume of the selected route. |
Unit |
setOnPrepareTransferListener(@Nullable listener: MediaRouter.OnPrepareTransferListener?) Sets a listener for receiving events when the selected route is about to be changed. |
Unit |
setRouterParams(@Nullable params: MediaRouterParams?) Sets |
Unit |
Unselects the current route and selects the default route instead. |
MediaRouter.RouteInfo |
updateSelectedRoute(@NonNull selector: MediaRouteSelector) Returns the selected route if it matches the specified selector, otherwise selects the default route and returns it. |
Constants
AVAILABILITY_FLAG_IGNORE_DEFAULT_ROUTE
static val AVAILABILITY_FLAG_IGNORE_DEFAULT_ROUTE: Int
Flag for isRouteAvailable
: Ignore the default route.
This flag is used to determine whether a matching non-default route is available. This constraint may be used to decide whether to offer the route chooser dialog to the user. There is no point offering the chooser if there are no non-default choices.
Value: 1 << 0
AVAILABILITY_FLAG_REQUIRE_MATCH
static val AVAILABILITY_FLAG_REQUIRE_MATCH: Int
Flag for isRouteAvailable
: Require an actual route to be matched.
If this flag is not set, then isRouteAvailable
will return true if it is possible to discover a matching route even if discovery is not in progress or if no matching route has yet been found. This feature is used to save resources by removing the need to perform passive route discovery on low-RAM devices
.
If this flag is set, then isRouteAvailable
will only return true if a matching route has actually been discovered.
Value: 1 << 1
CALLBACK_FLAG_FORCE_DISCOVERY
static val CALLBACK_FLAG_FORCE_DISCOVERY: Int
Flag for #addCallback: Request passive route discovery while this callback is registered, even on low-RAM devices
.
This flag has a significant performance impact on low-RAM devices since it may cause many media route providers to be started simultaneously. It is much better to use CALLBACK_FLAG_REQUEST_DISCOVERY
instead to avoid performing passive discovery on these devices altogether. Refer to addCallback
for details.
Value: 1 << 3
See Also
CALLBACK_FLAG_PERFORM_ACTIVE_SCAN
static val CALLBACK_FLAG_PERFORM_ACTIVE_SCAN: Int
Flag for #addCallback: Actively scan for routes while this callback is registered.
When this flag is specified, the media router will actively scan for new routes. Certain routes, such as wifi display routes, may not be discoverable except when actively scanning. This flag is typically used when the route picker dialog has been opened by the user to ensure that the route information is up to date.
Active scanning may consume a significant amount of power and may have intrusive effects on wireless connectivity. Therefore it is important that active scanning only be requested when it is actually needed to satisfy a user request to discover and select a new route.
This flag implies CALLBACK_FLAG_REQUEST_DISCOVERY
but performing active scans is much more expensive than a normal discovery request.
Value: 1 << 0
See Also
CALLBACK_FLAG_REQUEST_DISCOVERY
static val CALLBACK_FLAG_REQUEST_DISCOVERY: Int
Flag for #addCallback: Request passive route discovery while this callback is registered, except on low-RAM devices
.
When this flag is specified, the media router will try to discover routes. Although route discovery is intended to be efficient, checking for new routes may result in some network activity and could slowly drain the battery. Therefore applications should only specify CALLBACK_FLAG_REQUEST_DISCOVERY
when they are running in the foreground and would like to provide the user with the option of connecting to new routes.
Applications should typically add a callback using this flag in the activity's
onStart
method and remove it in the onStop
method. The MediaRouteDiscoveryFragment
fragment may also be used for this purpose.
On low-RAM devices
this flag will be ignored. Refer to addCallback
for details.
Value: 1 << 2
See Also
CALLBACK_FLAG_UNFILTERED_EVENTS
static val CALLBACK_FLAG_UNFILTERED_EVENTS: Int
Flag for #addCallback: Do not filter route events.
When this flag is specified, the callback