java.lang.Object | |
↳ | android.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 is retrieved through Context.getSystemService()
of a Context.MEDIA_ROUTER_SERVICE
.
The media router API is not thread-safe; all interactions with it must be done from the main thread of the process.
Nested Classes | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
MediaRouter.Callback | Interface for receiving events about media routing changes. | ||||||||||
MediaRouter.RouteCategory | Definition of a category of routes. | ||||||||||
MediaRouter.RouteGroup | Information about a route that consists of multiple other routes in a group. | ||||||||||
MediaRouter.RouteInfo | Information about a media route. | ||||||||||
MediaRouter.SimpleCallback | Stub implementation of MediaRouter.Callback . |
||||||||||
MediaRouter.UserRouteInfo | Information about a route that the application may define and modify. | ||||||||||
MediaRouter.VolumeCallback | Interface for receiving events about volume changes. |
Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
int | CALLBACK_FLAG_PERFORM_ACTIVE_SCAN | Flag for addCallback(int, MediaRouter.Callback) : Actively scan for routes while this callback
is registered. |
|||||||||
int | CALLBACK_FLAG_UNFILTERED_EVENTS | Flag for addCallback(int, MediaRouter.Callback) : Do not filter route events. |
|||||||||
int | ROUTE_TYPE_LIVE_AUDIO | Route type flag for live audio. | |||||||||
int | ROUTE_TYPE_LIVE_VIDEO | Route type flag for live video. | |||||||||
int | ROUTE_TYPE_USER | Route type flag for application-specific usage. |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Add a callback to listen to events about specific kinds of media routes.
| |||||||||||
Add a callback to listen to events about specific kinds of media routes.
| |||||||||||
Add an app-specified route for media to the MediaRouter.
| |||||||||||
Remove all app-specified routes from the MediaRouter.
| |||||||||||
Create a new route category.
| |||||||||||
Create a new route category.
| |||||||||||
Create a new user route that may be modified and registered for use by the application.
| |||||||||||
Return the
category at the given index. | |||||||||||
Return the number of
categories currently
represented by routes known to this MediaRouter. | |||||||||||
Gets the default route for playing media content on the system.
| |||||||||||
Return the route at the specified index.
| |||||||||||
Return the number of
routes currently known
to this MediaRouter. | |||||||||||
Return the currently selected route for any of the given types
| |||||||||||
Remove the specified callback.
| |||||||||||
Remove an app-specified route for media from the MediaRouter.
| |||||||||||
Select the specified route to use for output of the given media types.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
|
Flag for addCallback(int, MediaRouter.Callback)
: 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.
Flag for addCallback(int, MediaRouter.Callback)
: Do not filter route events.
When this flag is specified, the callback will be invoked for event that affect any route event if they do not match the callback's associated media route selector.
Route type flag for live audio.
A device that supports live audio routing will allow the media audio stream to be routed to supported destinations. This can include internal speakers or audio jacks on the device itself, A2DP devices, and more.
Once initiated this routing is transparent to the application. All audio played on the media stream will be routed to the selected destination.
Route type flag for live video.
A device that supports live video routing will allow a mirrored version
of the device's primary display or a customized
Presentation
to be routed to supported destinations.
Once initiated, display mirroring is transparent to the application.
While remote routing is active the application may use a
Presentation
to replace the mirrored view
on the external display with different content.
Route type flag for application-specific usage.
Unlike other media route types, user routes are managed by the application. The MediaRouter will manage and dispatch events for user routes, but the application is expected to interpret the meaning of these events and perform the requested routing tasks.
Add a callback to listen to events about specific kinds of media routes. If the specified callback is already registered, its registration will be updated for any additional route types specified.
This is a convenience method that has the same effect as calling
addCallback(int, Callback, int)
without flags.
types | Types of routes this callback is interested in |
---|---|
cb | Callback to add |
Add a callback to listen to events about specific kinds of media routes. If the specified callback is already registered, its registration will be updated for any additional route types specified.
By default, the callback will only be invoked for events that affect routes
that match the specified selector. The filtering may be disabled by specifying
the CALLBACK_FLAG_UNFILTERED_EVENTS
flag.
types | Types of routes this callback is interested in |
---|---|
cb | Callback to add |
flags | Flags to control the behavior of the callback.
May be zero or a combination of CALLBACK_FLAG_PERFORM_ACTIVE_SCAN and
CALLBACK_FLAG_UNFILTERED_EVENTS .
|
Add an app-specified route for media to the MediaRouter.
App-specified route definitions are created using createUserRoute(RouteCategory)
info | Definition of the route to add |
---|
Remove all app-specified routes from the MediaRouter.
Create a new route category. Each route must belong to a category.
name | Name of the new category |
---|---|
isGroupable | true if routes in this category may be grouped with one another |
Create a new route category. Each route must belong to a category.
nameResId | Resource ID of the name of the new category |
---|---|
isGroupable | true if routes in this category may be grouped with one another |
Create a new user route that may be modified and registered for use by the application.
category | The category the new route will belong to |
---|
Return the category
at the given index.
Valid indices are in the range [0-getCategoryCount).
index | which category to return |
---|
Return the number of categories
currently
represented by routes known to this MediaRouter.
Gets the default route for playing media content on the system.
The system always provides a default route.
Return the route at the specified index.
index | index of the route to return |
---|
Return the number of routes
currently known
to this MediaRouter.
Return the currently selected route for any of the given types
type | route types |
---|
Remove the specified callback. It will no longer receive events about media routing.
cb | Callback to remove |
---|
Remove an app-specified route for media from the MediaRouter.
info | Definition of the route to remove |
---|
Select the specified route to use for output of the given media types.
As API version 18, this function may be used to select any route. In prior versions, this function could only be used to select user routes and would ignore any attempt to select a system route.
types | type flags indicating which types this route should be used for. The route must support at least a subset. |
---|---|
route | Route to select |