MediaSession2
open class MediaSession2 : AutoCloseable
| kotlin.Any | |
| ↳ | 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 | |
|---|---|
|
This API is not generally intended for third party application developers. |
|
|
This API is not generally intended for third party application developers. |
|
| abstract |
This API is not generally intended for third party application developers. |
| Public methods | |
|---|---|
| open Unit |
broadcastSessionCommand(command: Session2Command, args: Bundle?)Broadcasts a session command to all the connected controllers |
| open Unit |
cancelSessionCommand(controller: MediaSession2.ControllerInfo, token: Any)Cancels the session command previously sent. |
| open Unit |
close() |
| open MutableList<MediaSession2.ControllerInfo!> |
Gets the list of the connected controllers |
| open String |
getId()Returns the session ID |
| open Session2Token |
getToken()Returns the |
| open Boolean |
Returns whether the playback is active (i.e. playing something) |
| open Any |
sendSessionCommand(controller: MediaSession2.ControllerInfo, command: Session2Command, args: Bundle?)Sends a session command to a specific controller |
| open Unit |
setPlaybackActive(playbackActive: Boolean)Sets whether the playback is active (i.e. playing something) |
Public methods
broadcastSessionCommand
open fun broadcastSessionCommand(
command: Session2Command,
args: Bundle?
): Unit
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
open fun cancelSessionCommand(
controller: MediaSession2.ControllerInfo,
token: Any
): Unit
Cancels the session command previously sent.
| Parameters | |
|---|---|
controller |
MediaSession2.ControllerInfo: the controller to get the session command This value cannot be null. |
token |
Any: the token which is returned from sendSessionCommand. This value cannot be null. |
close
open fun close(): Unit
| Exceptions | |
|---|---|
java.lang.Exception |
if this resource cannot be closed |
getConnectedControllers
open fun getConnectedControllers(): MutableList<MediaSession2.ControllerInfo!>
Gets the list of the connected controllers
| Return | |
|---|---|
MutableList<MediaSession2.ControllerInfo!> |
list of the connected controllers. This value cannot be null. |
getId
open fun getId(): String
Returns the session ID
| Return | |
|---|---|
String |
This value cannot be null. |
getToken
open fun getToken(): Session2Token
Returns the Session2Token for creating MediaController2.
| Return | |
|---|---|
Session2Token |
This value cannot be null. |
isPlaybackActive
open fun isPlaybackActive(): Boolean
Returns whether the playback is active (i.e. playing something)
| Return | |
|---|---|
Boolean |
true if the playback active, false otherwise. |
sendSessionCommand
open fun sendSessionCommand(
controller: MediaSession2.ControllerInfo,
command: Session2Command,
args: Bundle?
): Any
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. |
| Return | |
|---|---|
Any |
a token which will be sent together in SessionCallback.onCommandResult when its result is received. This value cannot be null. |
setPlaybackActive
open fun setPlaybackActive(playbackActive: Boolean): Unit
Sets whether the playback is active (i.e. playing something)
| Parameters | |
|---|---|
playbackActive |
Boolean: true if the playback active, false otherwise. |