Added in API level 29

MediaSession2

open class MediaSession2 : AutoCloseable
kotlin.Any
   ↳ android.media.MediaSession2

This API is not generally intended for third party application developers. Use the AndroidX Media2 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

Broadcasts a session command to all the connected controllers

open Unit

Cancels the session command previously sent.

open Unit

open MutableList<MediaSession2.ControllerInfo!>

Gets the list of the connected controllers

open String

Returns the session ID

open Session2Token

Returns the Session2Token for creating MediaController2.

open Boolean

Returns whether the playback is active (i.e. playing something)

open Any

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

Added in API level 29
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

Added in API level 29
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

Added in API level 29
open fun close(): Unit
Exceptions
java.lang.Exception if this resource cannot be closed

getConnectedControllers

Added in API level 29
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

Added in API level 29
open fun getId(): String

Returns the session ID

Return
String This value cannot be null.

getToken

Added in API level 29
open fun getToken(): Session2Token

Returns the Session2Token for creating MediaController2.

Return
Session2Token This value cannot be null.

isPlaybackActive

Added in API level 29
open fun isPlaybackActive(): Boolean

Returns whether the playback is active (i.e. playing something)

Return
Boolean true if the playback active, false otherwise.

sendSessionCommand

Added in API level 29
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

Added in API level 29
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.