MediaSession2
public
class
MediaSession2
extends Object
implements
AutoCloseable
| java.lang.Object | |
| ↳ | android.media.MediaSession2 |
This API is not generally intended for third party application developers. Use the AndroidX Media3 session Library for consistent behavior across all devices.
Allows a media app to expose its transport controls and playback information in a process to other processes including the Android framework and other apps.
Summary
Nested classes | |
|---|---|
class |
MediaSession2.Builder
This API is not generally intended for third party application developers. |
class |
MediaSession2.ControllerInfo
This API is not generally intended for third party application developers. |
class |
MediaSession2.SessionCallback
This API is not generally intended for third party application developers. |
Public methods | |
|---|---|
void
|
broadcastSessionCommand(Session2Command command, Bundle args)
Broadcasts a session command to all the connected controllers
|
void
|
cancelSessionCommand(MediaSession2.ControllerInfo controller, Object token)
Cancels the session command previously sent. |
void
|
close()
Closes this resource, relinquishing any underlying resources. |
List<MediaSession2.ControllerInfo>
|
getConnectedControllers()
Gets the list of the connected controllers |
String
|
getId()
Returns the session ID |
Session2Token
|
getToken()
Returns the |
boolean
|
isPlaybackActive()
Returns whether the playback is active (i.e. |
Object
|
sendSessionCommand(MediaSession2.ControllerInfo controller, Session2Command command, Bundle args)
Sends a session command to a specific controller
|
void
|
setPlaybackActive(boolean playbackActive)
Sets whether the playback is active (i.e. |
Inherited methods | |
|---|---|
Public methods
broadcastSessionCommand
public void broadcastSessionCommand (Session2Command command, Bundle args)
Broadcasts a session command to all the connected controllers
| Parameters | |
|---|---|
command |
Session2Command: the session command
This value cannot be null. |
args |
Bundle: optional arguments
This value may be null. |
cancelSessionCommand
public void cancelSessionCommand (MediaSession2.ControllerInfo controller, Object token)
Cancels the session command previously sent.
| Parameters | |
|---|---|
controller |
MediaSession2.ControllerInfo: the controller to get the session command
This value cannot be null. |
token |
Object: the token which is returned from sendSessionCommand(ControllerInfo, Session2Command, Bundle).
This value cannot be null. |
close
public void close ()
Closes this resource, relinquishing any underlying resources.
This method is invoked automatically on objects managed by the
try-with-resources statement.
getConnectedControllers
public List<MediaSession2.ControllerInfo> getConnectedControllers ()
Gets the list of the connected controllers
| Returns | |
|---|---|
List<MediaSession2.ControllerInfo> |
list of the connected controllers.
This value cannot be null. |
getId
public String getId ()
Returns the session ID
| Returns | |
|---|---|
String |
This value cannot be null. |
getToken
public Session2Token getToken ()
Returns the Session2Token for creating MediaController2.
| Returns | |
|---|---|
Session2Token |
This value cannot be null. |
isPlaybackActive
public boolean isPlaybackActive ()
Returns whether the playback is active (i.e. playing something)
| Returns | |
|---|---|
boolean |
true if the playback active, false otherwise. |
sendSessionCommand
public Object sendSessionCommand (MediaSession2.ControllerInfo controller, Session2Command command, Bundle args)
Sends a session command to a specific controller
| Parameters | |
|---|---|
controller |
MediaSession2.ControllerInfo: the controller to get the session command
This value cannot be null. |
command |
Session2Command: the session command
This value cannot be null. |
args |
Bundle: optional arguments
This value may be null. |
| Returns | |
|---|---|
Object |
a token which will be sent together in SessionCallback.onCommandResult
when its result is received.
This value cannot be null. |
setPlaybackActive
public void setPlaybackActive (boolean playbackActive)
Sets whether the playback is active (i.e. playing something)
| Parameters | |
|---|---|
playbackActive |
boolean: true if the playback active, false otherwise. |
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-02-10 UTC.