public final class

MediaLibraryService.MediaLibrarySession.Builder

extends androidx.media3.session.MediaSession.BuilderBase<MediaLibraryService.MediaLibrarySession, MediaLibraryService.MediaLibrarySession.Builder, MediaLibraryService.MediaLibrarySession.Callback>

 java.lang.Object

↳androidx.media3.session.MediaSession.BuilderBase<MediaLibraryService.MediaLibrarySession, MediaLibraryService.MediaLibrarySession.Builder, MediaLibraryService.MediaLibrarySession.Callback>

↳androidx.media3.session.MediaLibraryService.MediaLibrarySession.Builder

Overview

A builder for MediaLibraryService.MediaLibrarySession.

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

Summary

Constructors
publicBuilder(Context context, Player player, MediaLibraryService.MediaLibrarySession.Callback callback)

Creates a builder for MediaLibraryService.MediaLibrarySession.

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

Creates a builder for MediaLibraryService.MediaLibrarySession.

Methods
public MediaLibraryService.MediaLibrarySessionbuild()

Builds a MediaLibraryService.MediaLibrarySession.

public MediaLibraryService.MediaLibrarySession.BuildersetBitmapLoader(BitmapLoader bitmapLoader)

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

public MediaLibraryService.MediaLibrarySession.BuildersetCustomLayout(java.util.List<CommandButton> customLayout)

Sets the custom layout of the session.

public MediaLibraryService.MediaLibrarySession.BuildersetExtras(Bundle tokenExtras)

Sets an extras for the session token.

public MediaLibraryService.MediaLibrarySession.BuildersetId(java.lang.String id)

Sets an ID of the MediaLibraryService.MediaLibrarySession.

public MediaLibraryService.MediaLibrarySession.BuildersetLibraryErrorReplicationMode(int libraryErrorReplicationMode)

Sets whether library result errors should be replicated to the platform media session's as a fatal error, a non-fatal error or not replicated at all.

public MediaLibraryService.MediaLibrarySession.BuildersetPeriodicPositionUpdateEnabled(boolean isEnabled)

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

public MediaLibraryService.MediaLibrarySession.BuildersetSessionActivity(PendingIntent pendingIntent)

Sets a PendingIntent to launch an for the MediaLibraryService.MediaLibrarySession.

public MediaLibraryService.MediaLibrarySession.BuildersetSessionExtras(Bundle sessionExtras)

Sets the session extras.

public MediaLibraryService.MediaLibrarySession.BuildersetShowPlayButtonIfPlaybackIsSuppressed(boolean showPlayButtonIfPlaybackIsSuppressed)

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

from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructors

Creates a builder for MediaLibraryService.MediaLibrarySession.

Parameters:

service: The MediaLibraryService that instantiates the MediaLibraryService.MediaLibrarySession.
player: The underlying player to perform playback and handle transport controls.
callback: The callback to handle requests from MediaBrowser.

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

Creates a builder for MediaLibraryService.MediaLibrarySession.

Parameters:

context: The .
player: The underlying player to perform playback and handle transport controls.
callback: The callback to handle requests from MediaBrowser.

Methods

public MediaLibraryService.MediaLibrarySession.Builder setSessionActivity(PendingIntent pendingIntent)

Sets a PendingIntent to launch an for the MediaLibraryService.MediaLibrarySession. This can be used as a quick link to an ongoing media screen.

Parameters:

pendingIntent: The pending intent.

Returns:

The builder to allow chaining.

public MediaLibraryService.MediaLibrarySession.Builder setId(java.lang.String id)

Sets an ID of the MediaLibraryService.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:

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

Returns:

The builder to allow chaining.

public MediaLibraryService.MediaLibrarySession.Builder setExtras(Bundle tokenExtras)

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

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

Parameters:

tokenExtras: The extras .

Returns:

The builder to allow chaining.

public MediaLibraryService.MediaLibrarySession.Builder setSessionExtras(Bundle sessionExtras)

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

A controller has access to session extras through MediaController.getSessionExtras().

Parameters:

sessionExtras: The session extras .

Returns:

The builder to allow chaining.

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

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: The bitmap loader BitmapLoader.

Returns:

The builder to allow chaining.

public MediaLibraryService.MediaLibrarySession.Builder setCustomLayout(java.util.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 .

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

Use MediaSession.setCustomLayout(MediaSession.ControllerInfo, List) to update the custom layout during the lifetime of the session.

Parameters:

customLayout: The ordered list of command buttons.

Returns:

The builder to allow chaining.

public MediaLibraryService.MediaLibrarySession.Builder setShowPlayButtonIfPlaybackIsSuppressed(boolean showPlayButtonIfPlaybackIsSuppressed)

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

The default is true.

Parameters:

showPlayButtonIfPlaybackIsSuppressed: Whether to show a play button if playback is suppressed.

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:

isEnabled: Whether periodic position update is enabled.

public MediaLibraryService.MediaLibrarySession.Builder setLibraryErrorReplicationMode(int libraryErrorReplicationMode)

Sets whether library result errors should be replicated to the platform media session's as a fatal error, a non-fatal error or not replicated at all. Replication is only executed for calling legacy browsers (android.support.v4.media.MediaBrowserCompat and ) to which no error codes can be transmitted as a result of the service call.

The default is MediaLibraryService.MediaLibrarySession.LIBRARY_ERROR_REPLICATION_MODE_FATAL.

MediaLibraryService.MediaLibrarySession.Callback.onGetLibraryRoot(MediaLibraryService.MediaLibrarySession, MediaSession.ControllerInfo, MediaLibraryService.LibraryParams) is exempted from replication, because this method is part of the connection process of a legacy browser.

The following error codes are replicated:

See MediaLibraryService.MediaLibrarySession.clearReplicatedLibraryError() also.

Parameters:

libraryErrorReplicationMode: The mode to use.

Builds a MediaLibraryService.MediaLibrarySession.

Returns:

A new session.