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

MediaLibraryService.MediaLibrarySession.Builder

public static final class MediaLibraryService.MediaLibrarySession.Builder
extends Object

java.lang.Object
   ↳ androidx.media2.session.MediaLibraryService.MediaLibrarySession.Builder


Builder for MediaLibraryService.MediaLibrarySession.

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

MediaLibraryService.MediaLibrarySession.Builder(MediaLibraryService service, SessionPlayer player, Executor callbackExecutor, MediaLibraryService.MediaLibrarySession.MediaLibrarySessionCallback callback)

Public methods

MediaLibraryService.MediaLibrarySession build()

Build MediaSession.

MediaLibraryService.MediaLibrarySession.Builder setExtras(Bundle extras)

Set extras for the session token.

MediaLibraryService.MediaLibrarySession.Builder setId(String id)

Set ID of the session.

MediaLibraryService.MediaLibrarySession.Builder setSessionActivity(PendingIntent pi)

Set an intent for launching UI for this Session.

Inherited methods

Public constructors

MediaLibraryService.MediaLibrarySession.Builder

public MediaLibraryService.MediaLibrarySession.Builder (MediaLibraryService service, 
                SessionPlayer player, 
                Executor callbackExecutor, 
                MediaLibraryService.MediaLibrarySession.MediaLibrarySessionCallback callback)

Parameters
service MediaLibraryService

player SessionPlayer

callbackExecutor Executor

callback MediaLibraryService.MediaLibrarySession.MediaLibrarySessionCallback

Public methods

setExtras

public MediaLibraryService.MediaLibrarySession.Builder setExtras (Bundle extras)

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

Parameters
extras Bundle

Returns
MediaLibraryService.MediaLibrarySession.Builder The Builder to allow chaining

setId

public MediaLibraryService.MediaLibrarySession.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
MediaLibraryService.MediaLibrarySession.Builder

setSessionActivity

public MediaLibraryService.MediaLibrarySession.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
MediaLibraryService.MediaLibrarySession.Builder