# Print output for @column tags ?>
public
final
class
MediaRouter2
extends Object
java.lang.Object | |
↳ | android.media.MediaRouter2 |
This API is not generally intended for third party application developers. Use the AndroidX Media Router Library for consistent behavior across all devices. Media Router 2 allows applications to control the routing of media channels and streams from the current device to remote speakers and devices.
Nested classes | |
---|---|
class |
MediaRouter2.ControllerCallback
Callback for receiving |
interface |
MediaRouter2.OnGetControllerHintsListener
A listener interface to send optional app-specific hints when creating a
|
class |
MediaRouter2.RouteCallback
Callback for receiving events about media route discovery. |
class |
MediaRouter2.RoutingController
A class to control media routing session in media route provider. |
class |
MediaRouter2.TransferCallback
Callback for receiving events on media transfer. |
Public methods | |
---|---|
MediaRouter2.RoutingController
|
getController(String id)
Gets a |
List<MediaRouter2.RoutingController>
|
getControllers()
Gets the list of currently active |
static
MediaRouter2
|
getInstance(Context context)
Gets an instance of the media router associated with the context. |
List<MediaRoute2Info>
|
getRoutes()
Gets the unmodifiable list of |
MediaRouter2.RoutingController
|
getSystemController()
Gets a |
void
|
registerControllerCallback(Executor executor, MediaRouter2.ControllerCallback callback)
Registers a |
void
|
registerRouteCallback(Executor executor, MediaRouter2.RouteCallback routeCallback, RouteDiscoveryPreference preference)
Registers a callback to discover routes and to receive events when they change. |
void
|
registerTransferCallback(Executor executor, MediaRouter2.TransferCallback callback)
Registers a callback to get the result of |
void
|
setOnGetControllerHintsListener(MediaRouter2.OnGetControllerHintsListener listener)
Sets an |
void
|
stop()
Stops the current media routing. |
void
|
transferTo(MediaRoute2Info route)
Transfers the current media to the given route. |
void
|
unregisterControllerCallback(MediaRouter2.ControllerCallback callback)
Unregisters a |
void
|
unregisterRouteCallback(MediaRouter2.RouteCallback routeCallback)
Unregisters the given callback. |
void
|
unregisterTransferCallback(MediaRouter2.TransferCallback callback)
Unregisters the given callback. |
Inherited methods | |
---|---|
public MediaRouter2.RoutingController getController (String id)
Gets a RoutingController
whose ID is equal to the given ID.
Returns null
if there is no matching controller.
Parameters | |
---|---|
id |
String : This value cannot be null . |
Returns | |
---|---|
MediaRouter2.RoutingController |
public List<MediaRouter2.RoutingController> getControllers ()
Gets the list of currently active routing controllers
on which
media can be played.
Note: The list returned here will never be empty. The first element in the list is
always the system controller
.
Returns | |
---|---|
List<MediaRouter2.RoutingController> |
This value cannot be null . |
public static MediaRouter2 getInstance (Context context)
Gets an instance of the media router associated with the context.
Parameters | |
---|---|
context |
Context : This value cannot be null . |
Returns | |
---|---|
MediaRouter2 |
This value cannot be null . |
public List<MediaRoute2Info> getRoutes ()
Gets the unmodifiable list of routes
currently
known to the media router.
Please note that the list can be changed before callbacks are invoked.
Returns | |
---|---|
List<MediaRoute2Info> |
the list of routes that contains at least one of the route features in discovery
preferences registered by the application
This value cannot be null . |
public MediaRouter2.RoutingController getSystemController ()
Gets a RoutingController
which can control the routes provided by system.
e.g. Phone speaker, wired headset, Bluetooth, etc.
Note: The system controller can't be released. Calling RoutingController#release()
will be ignored.
This method always returns the same instance.
Returns | |
---|---|
MediaRouter2.RoutingController |
This value cannot be null . |
public void registerControllerCallback (Executor executor, MediaRouter2.ControllerCallback callback)
Registers a ControllerCallback
.
If you register the same callback twice or more, it will be ignored.
Parameters | |
---|---|
executor |
Executor : This value cannot be null .
Callback and listener events are dispatched through this
Executor , providing an easy way to control which thread is
used. To dispatch events through the main thread of your
application, you can use
Context.getMainExecutor() .
To dispatch events through a shared thread pool, you can use
AsyncTask#THREAD_POOL_EXECUTOR . |
callback |
MediaRouter2.ControllerCallback : This value cannot be null . |
public void registerRouteCallback (Executor executor, MediaRouter2.RouteCallback routeCallback, RouteDiscoveryPreference preference)
Registers a callback to discover routes and to receive events when they change.
If the specified callback is already registered, its registration will be updated for the
given executor
and discovery preference
.
Parameters | |
---|---|
executor |
Executor : This value cannot be null .
Callback and listener events are dispatched through this
Executor , providing an easy way to control which thread is
used. To dispatch events through the main thread of your
application, you can use
Context.getMainExecutor() .
To dispatch events through a shared thread pool, you can use
AsyncTask#THREAD_POOL_EXECUTOR . |
routeCallback |
MediaRouter2.RouteCallback : This value cannot be null . |
preference |
RouteDiscoveryPreference : This value cannot be null . |
public void registerTransferCallback (Executor executor, MediaRouter2.TransferCallback callback)
Registers a callback to get the result of transferTo(android.media.MediaRoute2Info)
.
If you register the same callback twice or more, it will be ignored.
Parameters | |
---|---|
executor |
Executor : the executor to execute the callback on
This value cannot be null .
Callback and listener events are dispatched through this
Executor , providing an easy way to control which thread is
used. To dispatch events through the main thread of your
application, you can use
Context.getMainExecutor() .
To dispatch events through a shared thread pool, you can use
AsyncTask#THREAD_POOL_EXECUTOR . |
callback |
MediaRouter2.TransferCallback : the callback to register
This value cannot be null . |
public void setOnGetControllerHintsListener (MediaRouter2.OnGetControllerHintsListener listener)
Sets an OnGetControllerHintsListener
to send hints when creating a
RoutingController
. To send the hints, listener should be set BEFORE calling
transferTo(android.media.MediaRoute2Info)
.
Parameters | |
---|---|
listener |
MediaRouter2.OnGetControllerHintsListener : A listener to send optional app-specific hints when creating a controller.
null for unset.
This value may be null . |
public void stop ()
Stops the current media routing. If the system controller
controls the media routing, this method is a no-op.
public void transferTo (MediaRoute2Info route)
Transfers the current media to the given route.
If it's necessary a new RoutingController
is created or it is handled within
the current routing controller.
Parameters | |
---|---|
route |
MediaRoute2Info : the route you want to transfer the current media to. Pass null to
stop routing of the current media.
This value cannot be null . |
public void unregisterControllerCallback (MediaRouter2.ControllerCallback callback)
Unregisters a ControllerCallback
. The callback will no longer receive
events. If the callback has not been added or been removed already, it is ignored.
Parameters | |
---|---|
callback |
MediaRouter2.ControllerCallback : This value cannot be null . |
public void unregisterRouteCallback (MediaRouter2.RouteCallback routeCallback)
Unregisters the given callback. The callback will no longer receive events. If the callback has not been added or been removed already, it is ignored.
Parameters | |
---|---|
routeCallback |
MediaRouter2.RouteCallback : the callback to unregister
This value cannot be null . |
public void unregisterTransferCallback (MediaRouter2.TransferCallback callback)
Unregisters the given callback. The callback will no longer receive events. If the callback has not been added or been removed already, it is ignored.
Parameters | |
---|---|
callback |
MediaRouter2.TransferCallback : the callback to unregister
This value cannot be null . |