public final class MediaController extends Object
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.
Modifier and Type | Class and Description |
---|---|
static class |
MediaController.Callback
Callback for receiving updates from the session.
|
static class |
MediaController.PlaybackInfo
Holds information about the current playback and how audio is handled for
this session.
|
class |
MediaController.TransportControls
Interface for controlling media playback on a session.
|
Constructor and Description |
---|
MediaController(Context context,
ISessionController sessionBinder)
Call for creating a MediaController directly from a binder.
|
Modifier and Type | Method and Description |
---|---|
void |
adjustVolume(int direction,
int flags)
Adjust the volume of the output this session is playing on.
|
boolean |
controlsSameSession(MediaController other) |
boolean |
dispatchMediaButtonEvent(KeyEvent keyEvent)
Send the specified media button event to the session.
|
Bundle |
getExtras()
Get the extras for this session.
|
long |
getFlags()
Get the flags for this session.
|
MediaMetadata |
getMetadata()
Get the current metadata for this session.
|
String |
getPackageName()
Get the session owner's package name.
|
MediaController.PlaybackInfo |
getPlaybackInfo()
Get the current playback info for this session.
|
PlaybackState |
getPlaybackState()
Get the current playback state for this session.
|
List<MediaSession.QueueItem> |
getQueue()
Get the current play queue for this session if one is set.
|
CharSequence |
getQueueTitle()
Get the queue title for this session.
|
int |
getRatingType()
Get the rating type supported by the session.
|
PendingIntent |
getSessionActivity()
Get an intent for launching UI associated with this session if one
exists.
|
MediaSession.Token |
getSessionToken()
Get the token for the session this is connected to.
|
String |
getTag()
Get the session's tag for debugging purposes.
|
MediaController.TransportControls |
getTransportControls()
Get a
MediaController.TransportControls instance to send transport actions to
the associated session. |
void |
registerCallback(MediaController.Callback callback)
Registers a callback to receive updates from the Session.
|
void |
registerCallback(MediaController.Callback callback,
Handler handler)
Registers a callback to receive updates from the session.
|
void |
sendCommand(String command,
Bundle args,
ResultReceiver cb)
Sends a generic command to the session.
|
void |
setVolumeTo(int value,
int flags)
Set the volume of the output this session is playing on.
|
void |
unregisterCallback(MediaController.Callback callback)
Unregisters the specified callback.
|
public MediaController(Context context, ISessionController sessionBinder)
public MediaController.TransportControls getTransportControls()
MediaController.TransportControls
instance to send transport actions to
the associated session.public boolean dispatchMediaButtonEvent(KeyEvent keyEvent)
keyEvent
- The media button event to dispatch.public PlaybackState getPlaybackState()
public MediaMetadata getMetadata()
public List<MediaSession.QueueItem> getQueue()
getMetadata()
should be used.public CharSequence getQueueTitle()
public Bundle getExtras()
public int getRatingType()
public long getFlags()
MediaSession
.public MediaController.PlaybackInfo getPlaybackInfo()
public PendingIntent getSessionActivity()
PendingIntent
to launch UI or null.public MediaSession.Token getSessionToken()
public void setVolumeTo(int value, int flags)
VolumeProvider.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.getPlaybackInfo()
public void adjustVolume(int direction, int flags)
AudioManager.ADJUST_LOWER
,
AudioManager.ADJUST_RAISE
, or AudioManager.ADJUST_SAME
.
The command will be ignored if the session does not support
VolumeProvider.VOLUME_CONTROL_RELATIVE
or
VolumeProvider.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.getPlaybackInfo()
public void registerCallback(MediaController.Callback callback)
callback
- The callback object, must not be null.public void registerCallback(MediaController.Callback callback, Handler handler)
callback
- The callback object, must not be null.handler
- The handler to post updates on. If null the callers thread
will be used.public void unregisterCallback(MediaController.Callback callback)
callback
- The callback to remove.public void sendCommand(String command, Bundle args, ResultReceiver cb)
command
- The command to sendargs
- Any parameters to include with the commandcb
- The callback to receive the result onpublic String getPackageName()
public String getTag()
public boolean controlsSameSession(MediaController other)