MediaSession.Builder

Added in 1.0.0
Deprecated in 1.3.0

class MediaSession.Builder


Builder for MediaSession.

Any incoming event from the MediaController will be handled on the callback executor. If it's not set, getMainExecutor will be used by default.

Summary

Public constructors

Builder(context: Context, player: SessionPlayer)

Public functions

MediaSession

Builds a MediaSession.

MediaSession.Builder
setExtras(extras: Bundle)

Sets extras for the session token.

MediaSession.Builder

Sets the ID of the session.

MediaSession.Builder

Sets an intent for launching UI for this Session.

MediaSession.Builder
setSessionCallback(
    executor: Executor,
    callback: MediaSession.SessionCallback
)

Sets callback for the session.

Public constructors

Builder

Added in 1.0.0
Deprecated in 1.3.0
Builder(context: Context, player: SessionPlayer)

Public functions

build

Added in 1.0.0
Deprecated in 1.3.0
fun build(): MediaSession

Builds a MediaSession.

Returns
MediaSession

a new session

Throws
java.lang.IllegalStateException

if the session with the same id already exists for the package.

setExtras

Added in 1.0.0
Deprecated in 1.3.0
fun setExtras(extras: Bundle): MediaSession.Builder

Sets extras for the session token. If not set, getExtras will return an empty Bundle.

Returns
MediaSession.Builder

the Builder to allow chaining

Throws
java.lang.IllegalArgumentException

if the bundle contains any non-framework Parcelable objects.

See also
getExtras

setId

Added in 1.0.0
Deprecated in 1.3.0
fun setId(id: String): MediaSession.Builder

Sets the ID of the session. If it's not set, an empty string will be used to create a session.

Use this if and only if your app supports multiple playback at the same time and also wants to provide external apps to have finer controls of them.

Parameters
id: String

id of the session. Must be unique per package.

setSessionActivity

Added in 1.0.0
Deprecated in 1.3.0
fun setSessionActivity(pi: PendingIntent?): MediaSession.Builder

Sets an intent for launching UI for this Session. This can be used as a quick link to an ongoing media screen. The intent should be for an activity that may be started using startActivity.

Parameters
pi: PendingIntent?

The intent to launch to show UI for this session.

setSessionCallback

Added in 1.0.0
Deprecated in 1.3.0
fun setSessionCallback(
    executor: Executor,
    callback: MediaSession.SessionCallback
): MediaSession.Builder

Sets callback for the session.

Parameters
executor: Executor

callback executor

callback: MediaSession.SessionCallback

session callback