public final class MediaSessionManager extends Object
media sessions
that applications have published to express their ongoing media playback
state.
Use Context.getSystemService(Context.MEDIA_SESSION_SERVICE)
to
get an instance of this class.
MediaSession
,
MediaController
Modifier and Type | Class and Description |
---|---|
static interface |
MediaSessionManager.OnActiveSessionsChangedListener
Listens for changes to the list of active sessions.
|
Constructor and Description |
---|
MediaSessionManager(Context context) |
Modifier and Type | Method and Description |
---|---|
void |
addOnActiveSessionsChangedListener(MediaSessionManager.OnActiveSessionsChangedListener sessionListener,
ComponentName notificationListener)
Add a listener to be notified when the list of active sessions
changes.This requires the
android.Manifest.permission.MEDIA_CONTENT_CONTROL permission be held by
the calling app.
|
void |
addOnActiveSessionsChangedListener(MediaSessionManager.OnActiveSessionsChangedListener sessionListener,
ComponentName notificationListener,
Handler handler)
Add a listener to be notified when the list of active sessions
changes.This requires the
android.Manifest.permission.MEDIA_CONTENT_CONTROL permission be held by
the calling app.
|
void |
addOnActiveSessionsChangedListener(MediaSessionManager.OnActiveSessionsChangedListener sessionListener,
ComponentName notificationListener,
int userId,
Handler handler)
Add a listener to be notified when the list of active sessions
changes.This requires the
android.Manifest.permission.MEDIA_CONTENT_CONTROL permission be held by
the calling app.
|
ISession |
createSession(MediaSession.CallbackStub cbStub,
String tag,
int userId)
Create a new session in the system and get the binder for it.
|
void |
dispatchAdjustVolume(int suggestedStream,
int direction,
int flags)
Dispatch an adjust volume request to the system.
|
void |
dispatchMediaKeyEvent(KeyEvent keyEvent)
Send a media key event.
|
void |
dispatchMediaKeyEvent(KeyEvent keyEvent,
boolean needWakeLock)
Send a media key event.
|
List<MediaController> |
getActiveSessions(ComponentName notificationListener)
Get a list of controllers for all ongoing sessions.
|
List<MediaController> |
getActiveSessionsForUser(ComponentName notificationListener,
int userId)
Get active sessions for a specific user.
|
boolean |
isGlobalPriorityActive()
Check if the global priority session is currently active.
|
void |
removeOnActiveSessionsChangedListener(MediaSessionManager.OnActiveSessionsChangedListener listener)
Stop receiving active sessions updates on the specified listener.
|
void |
setRemoteVolumeController(IRemoteVolumeController rvc)
Set the remote volume controller to receive volume updates on.
|
public MediaSessionManager(Context context)
public ISession createSession(MediaSession.CallbackStub cbStub, String tag, int userId) throws RemoteException
tag
- A short name for debugging purposes.RemoteException
public List<MediaController> getActiveSessions(ComponentName notificationListener)
This requires the android.Manifest.permission.MEDIA_CONTENT_CONTROL
permission be held by the calling app. You may also retrieve this list if
your app is an enabled notification listener using the
NotificationListenerService
APIs, in which case you must pass the
ComponentName
of your enabled listener.
notificationListener
- The enabled notification listener component.
May be null.public List<MediaController> getActiveSessionsForUser(ComponentName notificationListener, int userId)
android.Manifest.permission#INTERACT_ACROSS_USERS_FULL
permission
in addition to any other requirements. If you are an enabled notification
listener you may only get sessions for the users you are enabled for.notificationListener
- The enabled notification listener component.
May be null.userId
- The user id to fetch sessions for.public void addOnActiveSessionsChangedListener(MediaSessionManager.OnActiveSessionsChangedListener sessionListener, ComponentName notificationListener)
NotificationListenerService
APIs, in which case you must pass the
ComponentName
of your enabled listener. Updates will be posted to
the thread that registered the listener.sessionListener
- The listener to add.notificationListener
- The enabled notification listener component.
May be null.public void addOnActiveSessionsChangedListener(MediaSessionManager.OnActiveSessionsChangedListener sessionListener, ComponentName notificationListener, Handler handler)
NotificationListenerService
APIs, in which case you must pass the
ComponentName
of your enabled listener. Updates will be posted to
the handler specified or to the caller's thread if the handler is null.sessionListener
- The listener to add.notificationListener
- The enabled notification listener component.
May be null.handler
- The handler to post events to.public void addOnActiveSessionsChangedListener(MediaSessionManager.OnActiveSessionsChangedListener sessionListener, ComponentName notificationListener, int userId, Handler handler)
NotificationListenerService
APIs, in which case you must pass the
ComponentName
of your enabled listener.sessionListener
- The listener to add.notificationListener
- The enabled notification listener component.
May be null.userId
- The userId to listen for changes on.handler
- The handler to post updates on.public void removeOnActiveSessionsChangedListener(MediaSessionManager.OnActiveSessionsChangedListener listener)
listener
- The listener to remove.public void setRemoteVolumeController(IRemoteVolumeController rvc)
rvc
- The volume controller to receive updates on.public void dispatchMediaKeyEvent(KeyEvent keyEvent)
keyEvent
- The KeyEvent to send.public void dispatchMediaKeyEvent(KeyEvent keyEvent, boolean needWakeLock)
keyEvent
- The KeyEvent to send.needWakeLock
- True if a wake lock should be held while sending the key.public void dispatchAdjustVolume(int suggestedStream, int direction, int flags)
AudioManager.ADJUST_LOWER
, AudioManager.ADJUST_RAISE
,
AudioManager.ADJUST_SAME
.suggestedStream
- The stream to fall back to if there isn't a
relevant streamdirection
- The direction to adjust volume in.flags
- Any flags to include with the volume change.public boolean isGlobalPriorityActive()