The Android Developer Challenge is back! Submit your idea before December 2.

MediaSession.Builder

public static final class MediaSession.Builder
extends Object

java.lang.Object
   ↳ androidx.media2.session.MediaSession.Builder


Builder for MediaSession.

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

Summary

Public constructors

MediaSession.Builder(Context context, SessionPlayer player)

Public methods

MediaSession build()

Build MediaSession.

MediaSession.Builder setExtras(Bundle extras)

Set extras for the session token.

MediaSession.Builder setId(String id)

Set ID of the session.

MediaSession.Builder setSessionActivity(PendingIntent pi)

Set an intent for launching UI for this Session.

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

Set callback for the session.

Inherited methods

Public constructors

MediaSession.Builder

public MediaSession.Builder (Context context, 
                SessionPlayer player)

Parameters
context Context

player SessionPlayer

Public methods

build

public MediaSession build ()

Build MediaSession.

Returns
MediaSession a new session

setExtras

public MediaSession.Builder setExtras (Bundle extras)

Set extras for the session token. If not set, SessionToken.getExtras() will return Bundle.EMPTY.

Parameters
extras Bundle

Returns
MediaSession.Builder The Builder to allow chaining

setId

public MediaSession.Builder setId (String id)

Set 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.

Returns
MediaSession.Builder

setSessionActivity

public MediaSession.Builder setSessionActivity (PendingIntent pi)

Set 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 Context.startActivity(Intent).

Parameters
pi PendingIntent: The intent to launch to show UI for this session.

Returns
MediaSession.Builder

setSessionCallback

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

Set callback for the session.

Parameters
executor Executor: callback executor

callback MediaSession.SessionCallback: session callback.

Returns
MediaSession.Builder