java.lang.Object | |
↳ | android.media.session.MediaController |
Allows an app to interact with an ongoing media session. Media buttons and other commands can be sent to the session. A callback may be registered to receive updates from the session, such as metadata and play state changes.
A MediaController can be created through MediaSessionManager
if you
hold the "android.permission.MEDIA_CONTENT_CONTROL" permission or are an
enabled notification listener or by getting a MediaSession.Token
directly from the session owner.
MediaController objects are thread-safe.
Nested Classes | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
MediaController.Callback | Callback for receiving updates on from the session. | ||||||||||
MediaController.PlaybackInfo | Holds information about the current playback and how audio is handled for this session. | ||||||||||
MediaController.TransportControls | Interface for controlling media playback on a session. |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Create a new MediaController from a session's token.
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Adjust the volume of the output this session is playing on.
| |||||||||||
Send the specified media button event to the session.
| |||||||||||
Get the extras for this session.
| |||||||||||
Get the flags for this session.
| |||||||||||
Get the current metadata for this session.
| |||||||||||
Get the session owner's package name.
| |||||||||||
Get the current playback info for this session.
| |||||||||||
Get the current playback state for this session.
| |||||||||||
Get the current play queue for this session if one is set.
| |||||||||||
Get the queue title for this session.
| |||||||||||
Get the rating type supported by the session.
| |||||||||||
Get an intent for launching UI associated with this session if one
exists.
| |||||||||||
Get the token for the session this is connected to.
| |||||||||||
Get a
MediaController.TransportControls instance to send transport actions to
the associated session.
| |||||||||||
Registers a callback to receive updates from the session.
| |||||||||||
Registers a callback to receive updates from the Session.
| |||||||||||
Sends a generic command to the session.
| |||||||||||
Set the volume of the output this session is playing on.
| |||||||||||
Unregisters the specified callback.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
|
Create a new MediaController from a session's token.
context | The caller's context. |
---|---|
token | The token for the session. |
Adjust the volume of the output this session is playing on. The direction
must be one of ADJUST_LOWER
,
ADJUST_RAISE
, or ADJUST_SAME
.
The command will be ignored if the session does not support
VOLUME_CONTROL_RELATIVE
or
VOLUME_CONTROL_ABSOLUTE
. The flags in
AudioManager
may be used to affect the handling.
direction | The direction to adjust the volume in. |
---|---|
flags | Any flags to pass with the command. |
Send the specified media button event to the session. Only media keys can be sent by this method, other keys will be ignored.
keyEvent | The media button event to dispatch. |
---|
Get the flags for this session. Flags are defined in MediaSession
.
Get the current metadata for this session.
Get the session owner's package name.
Get the current playback info for this session.
Get the current playback state for this session.
Get the current play queue for this session if one is set. If you only
care about the current item getMetadata()
should be used.
Get the rating type supported by the session. One of:
Get an intent for launching UI associated with this session if one exists.
PendingIntent
to launch UI or null.
Get the token for the session this is connected to.
Get a MediaController.TransportControls
instance to send transport actions to
the associated session.
Registers a callback to receive updates from the session. Updates will be posted on the specified handler's thread.
callback | The callback object, must not be null. |
---|---|
handler | The handler to post updates on. If null the callers thread will be used. |
Registers a callback to receive updates from the Session. Updates will be posted on the caller's thread.
callback | The callback object, must not be null. |
---|
Sends a generic command to the session. It is up to the session creator to decide what commands and parameters they will support. As such, commands should only be sent to sessions that the controller owns.
command | The command to send |
---|---|
args | Any parameters to include with the command |
cb | The callback to receive the result on |
Set the volume of the output this session is playing on. The command will
be ignored if it does not support
VOLUME_CONTROL_ABSOLUTE
. The flags in
AudioManager
may be used to affect the handling.
value | The value to set it to, between 0 and the reported max. |
---|---|
flags | Flags from AudioManager to include with the volume
request.
|
Unregisters the specified callback. If an update has already been posted you may still receive it after calling this method.
callback | The callback to remove. |
---|