MediaLibraryService.MediaLibrarySession.Builder


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!,
    callback: MediaLibraryService.MediaLibrarySession.Callback!
)

Creates a builder for MediaLibrarySession.

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

Creates a builder for MediaLibrarySession.

Public functions

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 command buttons that can be added as supported media item commands.

MediaLibraryService.MediaLibrarySession.Builder!

Sets the custom layout of the session.

MediaLibraryService.MediaLibrarySession.Builder!
setExtras(tokenExtras: Bundle!)

Sets an extras Bundle for the session token.

MediaLibraryService.MediaLibrarySession.Builder!
setId(id: String!)

Sets an ID of the MediaLibrarySession.

MediaLibraryService.MediaLibrarySession.Builder!

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

MediaLibraryService.MediaLibrarySession.Builder!

Sets the media button preferences.

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(
    showPlayButtonIfPlaybackIsSuppressed: Boolean
)

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

Public constructors

Builder

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

Creates a builder for MediaLibrarySession.

Parameters
context: Context!

The Context.

player: Player!

The underlying player to perform playback and handle transport controls.

callback: MediaLibraryService.MediaLibrarySession.Callback!

The callback to handle requests from MediaBrowser.

Builder

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

Creates a builder for MediaLibrarySession.

Parameters
service: MediaLibraryService!

The MediaLibraryService that instantiates the .

player: Player!

The underlying player to perform playback and handle transport controls.

callback: MediaLibraryService.MediaLibrarySession.Callback!

The callback to handle requests from MediaBrowser.

Public functions

build

fun build(): MediaLibraryService.MediaLibrarySession!

Builds a MediaLibrarySession.

Returns
MediaLibraryService.MediaLibrarySession!

A new session.

Throws
java.lang.IllegalStateException

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

setBitmapLoader

@UnstableApi
fun setBitmapLoader(bitmapLoader: BitmapLoader!): MediaLibraryService.MediaLibrarySession.Builder!

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.

setCommandButtonsForMediaItems

@UnstableApi
fun setCommandButtonsForMediaItems(
    commandButtons: (Mutable)List<CommandButton!>!
): MediaLibraryService.MediaLibrarySession.Builder!

Sets command buttons that can be added as supported media item commands.

Parameters
commandButtons: (Mutable)List<CommandButton!>!

The command buttons.

setCustomLayout

@UnstableApi
@CanIgnoreReturnValue
fun setCustomLayout(customLayout: (Mutable)List<CommandButton!>!): MediaLibraryService.MediaLibrarySession.Builder!

Sets the custom layout of the session.

This method will be deprecated, prefer to use setMediaButtonPreferences. Note that the media button preferences use slots to define the allowed button placement.

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
customLayout: (Mutable)List<CommandButton!>!

The ordered list of command buttons.

Returns
MediaLibraryService.MediaLibrarySession.Builder!

The builder to allow chaining.

setExtras

fun setExtras(tokenExtras: Bundle!): MediaLibraryService.MediaLibrarySession.Builder!

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
tokenExtras: Bundle!

The extras Bundle.

Returns
MediaLibraryService.MediaLibrarySession.Builder!

The builder to allow chaining.

setId

fun setId(id: String!): MediaLibraryService.MediaLibrarySession.Builder!

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
id: String!

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

Returns
MediaLibraryService.MediaLibrarySession.Builder!

The builder to allow chaining.

setLibraryErrorReplicationMode

@UnstableApi
@CanIgnoreReturnValue
fun setLibraryErrorReplicationMode(libraryErrorReplicationMode: Int): MediaLibraryService.MediaLibrarySession.Builder!

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

The default is LIBRARY_ERROR_REPLICATION_MODE_FATAL.

onGetLibraryRoot is exempted from replication, because this method is part of the connection process of a legacy browser.

The following error codes are replicated:

See clearReplicatedLibraryError also.

Parameters
libraryErrorReplicationMode: Int

The mode to use.

setMediaButtonPreferences

@CanIgnoreReturnValue
@UnstableApi
fun setMediaButtonPreferences(
    mediaButtonPreferences: (Mutable)List<CommandButton!>!
): MediaLibraryService.MediaLibrarySession.Builder!

Sets the media button preferences.

The button 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 media button preferences of the session available with the initial connection result by default. Media button preferences specific to a controller can be set when the controller connects by using an ConnectionResult.AcceptedResultBuilder.

Use MediaSession.setMediaButtonPreferences(..) to update the media button preferences during the life time of the session.

On the controller side, the enabled flag is set to false if the available commands of a controller do not allow to use a button.

Parameters
mediaButtonPreferences: (Mutable)List<CommandButton!>!

The ordered list of command buttons.

Returns
MediaLibraryService.MediaLibrarySession.Builder!

The builder to allow chaining.

setPeriodicPositionUpdateEnabled

@UnstableApi
fun setPeriodicPositionUpdateEnabled(isEnabled: Boolean): MediaLibraryService.MediaLibrarySession.Builder!

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: Boolean

Whether periodic position update is enabled.

setSessionActivity

fun setSessionActivity(pendingIntent: PendingIntent!): MediaLibraryService.MediaLibrarySession.Builder!

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
fun setSessionExtras(sessionExtras: Bundle!): MediaLibraryService.MediaLibrarySession.Builder!

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

A controller has access to session extras through getSessionExtras.

Parameters
sessionExtras: Bundle!

The session extras Bundle.

Returns
MediaLibraryService.MediaLibrarySession.Builder!

The builder to allow chaining.

setShowPlayButtonIfPlaybackIsSuppressed

@UnstableApi
fun setShowPlayButtonIfPlaybackIsSuppressed(
    showPlayButtonIfPlaybackIsSuppressed: Boolean
): MediaLibraryService.MediaLibrarySession.Builder!

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

The default is true.

Parameters
showPlayButtonIfPlaybackIsSuppressed: Boolean

Whether to show a play button if playback is suppressed.