MediaLibraryService.MediaLibrarySession.Builder


public final class MediaLibraryService.MediaLibrarySession.Builder


A builder for MediaLibrarySession.

Any incoming requests from the MediaBrowser will be handled on the application thread of the underlying Player.

Summary

Public constructors

@UnstableApi
Builder(
    Context context,
    Player player,
    MediaLibraryService.MediaLibrarySession.Callback callback
)

Creates a builder for MediaLibrarySession.

Builder(
    MediaLibraryService service,
    Player player,
    MediaLibraryService.MediaLibrarySession.Callback callback
)

Creates a builder for MediaLibrarySession.

Public methods

MediaLibraryService.MediaLibrarySession

Builds a MediaLibrarySession.

MediaLibraryService.MediaLibrarySession.Builder

Sets a BitmapLoader for the MediaLibrarySession to decode bitmaps from compressed binary data or load bitmaps from Uri.

MediaLibraryService.MediaLibrarySession.Builder

Sets the custom layout of the session.

MediaLibraryService.MediaLibrarySession.Builder
setExtras(Bundle tokenExtras)

Sets an extras Bundle for the session token.

MediaLibraryService.MediaLibrarySession.Builder

Sets an ID of the MediaLibrarySession.

MediaLibraryService.MediaLibrarySession.Builder

Sets whether periodic position updates should be sent to controllers while playing.

MediaLibraryService.MediaLibrarySession.Builder

Sets a PendingIntent to launch an android.app.Activity for the .

MediaLibraryService.MediaLibrarySession.Builder

Sets the session extras.

MediaLibraryService.MediaLibrarySession.Builder
@UnstableApi
setShowPlayButtonIfPlaybackIsSuppressed(
    boolean showPlayButtonIfPlaybackIsSuppressed
)

Sets whether a play button is shown if playback is suppressed.

Public constructors

Builder

@UnstableApi
public Builder(
    Context context,
    Player player,
    MediaLibraryService.MediaLibrarySession.Callback callback
)

Creates a builder for MediaLibrarySession.

Parameters
Context context

The Context.

Player player

The underlying player to perform playback and handle transport controls.

MediaLibraryService.MediaLibrarySession.Callback callback

The callback to handle requests from MediaBrowser.

Builder

public Builder(
    MediaLibraryService service,
    Player player,
    MediaLibraryService.MediaLibrarySession.Callback callback
)

Creates a builder for MediaLibrarySession.

Parameters
MediaLibraryService service

The MediaLibraryService that instantiates the .

Player player

The underlying player to perform playback and handle transport controls.

MediaLibraryService.MediaLibrarySession.Callback callback

The callback to handle requests from MediaBrowser.

Public methods

build

public MediaLibraryService.MediaLibrarySession build()

Builds a MediaLibrarySession.

Throws
java.lang.IllegalStateException

if a MediaSession with the same ID already exists in the package.

setBitmapLoader

@UnstableApi
public MediaLibraryService.MediaLibrarySession.Builder setBitmapLoader(BitmapLoader bitmapLoader)

Sets a BitmapLoader for the MediaLibrarySession to decode bitmaps from compressed binary data or load bitmaps from Uri.

The provided instance will likely be called repeatedly with the same request, so it would be best if any provided instance does some caching. Simple caching can be added to any BitmapLoader implementation by wrapping it in CacheBitmapLoader before passing it to this method.

If no instance is set, a CacheBitmapLoader with a DataSourceBitmapLoader inside will be used.

Parameters
BitmapLoader bitmapLoader

The bitmap loader BitmapLoader.

Returns
MediaLibraryService.MediaLibrarySession.Builder

The builder to allow chaining.

setCustomLayout

@UnstableApi
public MediaLibraryService.MediaLibrarySession.Builder setCustomLayout(List<CommandButton> customLayout)

Sets the custom layout of the session.

The buttons are converted to custom actions in the legacy media session playback state for legacy controllers (see PlaybackStateCompat.Builder#addCustomAction(PlaybackStateCompat.CustomAction)). When converting, the custom extras of the session command is used for the extras of the legacy custom action.

Controllers that connect have the custom layout of the session available with the initial connection result by default. A custom layout specific to a controller can be set when the controller connects by using an ConnectionResult.AcceptedResultBuilder.

On the controller side, isEnabled is overridden according to the available commands of the controller.

Use setCustomLayout to update the custom layout during the lifetime of the session.

Parameters
List<CommandButton> customLayout

The ordered list of command buttons.

Returns
MediaLibraryService.MediaLibrarySession.Builder

The builder to allow chaining.

setExtras

public MediaLibraryService.MediaLibrarySession.Builder setExtras(Bundle tokenExtras)

Sets an extras Bundle for the session token. If not set, EMPTY is used.

A controller has access to these extras through the connected token.

Parameters
Bundle tokenExtras

The extras Bundle.

Returns
MediaLibraryService.MediaLibrarySession.Builder

The builder to allow chaining.

setId

public MediaLibraryService.MediaLibrarySession.Builder setId(String id)

Sets an ID of the MediaLibrarySession. If not set, an empty string will be used.

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-grained controls.

Parameters
String id

The ID. Must be unique among all sessions per package.

Returns
MediaLibraryService.MediaLibrarySession.Builder

The builder to allow chaining.

setPeriodicPositionUpdateEnabled

@UnstableApi
public MediaLibraryService.MediaLibrarySession.Builder setPeriodicPositionUpdateEnabled(boolean isEnabled)

Sets whether periodic position updates should be sent to controllers while playing. If false, no periodic position updates are sent to controllers.

The default is true.

Parameters
boolean isEnabled

Whether periodic position update is enabled.

setSessionActivity

public MediaLibraryService.MediaLibrarySession.Builder setSessionActivity(PendingIntent pendingIntent)

Sets a PendingIntent to launch an android.app.Activity for the . This can be used as a quick link to an ongoing media screen.

Parameters
PendingIntent pendingIntent

The pending intent.

Returns
MediaLibraryService.MediaLibrarySession.Builder

The builder to allow chaining.

setSessionExtras

@UnstableApi
public MediaLibraryService.MediaLibrarySession.Builder setSessionExtras(Bundle sessionExtras)

Sets the session extras. If not set, EMPTY is used.

A controller has access to session extras through getSessionExtras.

Parameters
Bundle sessionExtras

The session extras Bundle.

Returns
MediaLibraryService.MediaLibrarySession.Builder

The builder to allow chaining.

setShowPlayButtonIfPlaybackIsSuppressed

@UnstableApi
public MediaLibraryService.MediaLibrarySession.Builder setShowPlayButtonIfPlaybackIsSuppressed(
    boolean showPlayButtonIfPlaybackIsSuppressed
)

Sets whether a play button is shown if playback is suppressed.

The default is true.

Parameters
boolean showPlayButtonIfPlaybackIsSuppressed

Whether to show a play button if playback is suppressed.