java.lang.Object | |
↳ | android.support.v4.media.session.MediaControllerCompat |
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 if you have a MediaSessionCompat.Token
from the session owner.
MediaController objects are thread-safe.
This is a helper for accessing features in MediaSession
introduced after API level 4 in a backwards compatible fashion.
Nested Classes | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
MediaControllerCompat.Callback | Callback for receiving updates on from the session. | ||||||||||
MediaControllerCompat.PlaybackInfo | Holds information about the way volume is handled for this session. | ||||||||||
MediaControllerCompat.TransportControls | Interface for controlling media playback on a session. |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Creates a media controller from a session.
| |||||||||||
Creates a media controller from a session token which may have
been obtained from another process.
|
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.
| |||||||||||
Gets the underlying framework
MediaController object.
| |||||||||||
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 controller is connected to.
| |||||||||||
Get a
MediaControllerCompat.TransportControls instance for this session.
| |||||||||||
Adds a callback to receive updates from the Session.
| |||||||||||
Adds 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.
| |||||||||||
Stop receiving updates on the specified callback.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
|
Creates a media controller from a session.
session | The session to be controlled. |
---|
Creates a media controller from a session token which may have been obtained from another process.
sessionToken | The token of the session to be controlled. |
---|
RemoteException | if the session is not accessible. |
---|
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
MediaSessionCompat
.
Gets the underlying framework
MediaController
object.
This method is only supported on API 21+.
MediaController
object, or null if none.
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 controller is connected to.
Get a MediaControllerCompat.TransportControls
instance for this session.
Adds 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. |
---|
Adds 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. |
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 |
---|---|
params | 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.
|
Stop receiving updates on the specified callback. If an update has already been posted you may still receive it after calling this method.
callback | The callback to remove |
---|