MediaBrowser.Builder

Added in 1.0.0
Deprecated in 1.3.0

class MediaBrowser.Builder


Builder for MediaBrowser.

To set the token of the session for the controller to connect to, one of the setSessionToken or setSessionCompatToken should be called. Otherwise, the build will throw an .

Any incoming event from the MediaSession will be handled on the callback executor.

Summary

Public constructors

Builder(context: Context)

Public functions

MediaBrowser

Builds a MediaBrowser.

MediaBrowser.Builder
setConnectionHints(connectionHints: Bundle)

Sets the connection hints for the controller.

MediaBrowser.Builder
setControllerCallback(
    executor: Executor,
    callback: MediaBrowser.BrowserCallback
)

Sets the callback for the controller and its executor.

MediaBrowser.Builder

Sets the MediaSessionCompat.Token for the controller to connect to.

MediaBrowser.Builder

Sets the SessionToken for the controller to connect to.

Public constructors

Builder

Added in 1.0.0
Deprecated in 1.3.0
Builder(context: Context)

Public functions

build

Added in 1.0.0
Deprecated in 1.3.0
fun build(): MediaBrowser

Builds a MediaBrowser.

Returns
MediaBrowser

a new browser

setConnectionHints

Added in 1.0.0
Deprecated in 1.3.0
fun setConnectionHints(connectionHints: Bundle): MediaBrowser.Builder

Sets the connection hints for the controller.

connectionHints is a session-specific argument to send to the session when connecting. The contents of this bundle may affect the connection result.

The hints specified here are only used when when connecting to the MediaSession. They will be ignored when connecting to MediaSessionCompat.

Parameters
connectionHints: Bundle

a bundle which contains the connection hints

Returns
MediaBrowser.Builder

the Builder to allow chaining

Throws
java.lang.IllegalArgumentException

if the bundle contains any non-framework Parcelable objects.

setControllerCallback

Added in 1.0.0
Deprecated in 1.3.0
fun setControllerCallback(
    executor: Executor,
    callback: MediaBrowser.BrowserCallback
): MediaBrowser.Builder

Sets the callback for the controller and its executor.

Parameters
executor: Executor

callback executor

callback: MediaBrowser.BrowserCallback

controller callback.

Returns
MediaBrowser.Builder

the Builder to allow chaining

setSessionCompatToken

Added in 1.0.0
Deprecated in 1.3.0
fun setSessionCompatToken(compatToken: MediaSessionCompat.Token): MediaBrowser.Builder

Sets the MediaSessionCompat.Token for the controller to connect to.

When this method is called, the SessionToken which was set by calling setSessionToken is removed.

Parameters
compatToken: MediaSessionCompat.Token

token to connect to

Returns
MediaBrowser.Builder

the Builder to allow chaining

setSessionToken

Added in 1.0.0
Deprecated in 1.3.0
fun setSessionToken(token: SessionToken): MediaBrowser.Builder

Sets the SessionToken for the controller to connect to.

When this method is called, the MediaSessionCompat.Token which was set by calling setSessionCompatToken is removed.

Detailed behavior of the MediaController differs according to the type of the token as follows.

  1. Connected to a TYPE_SESSION token

    The controller connects to the specified session directly. It's recommended when you're sure which session to control, or a you've got token directly from the session app.

    This can be used only when the session for the token is running. Once the session is closed, the token becomes unusable.

  2. Connected to a TYPE_SESSION_SERVICE or TYPE_LIBRARY_SERVICE

    The controller connects to the session provided by the onGetSession. It's up to the service's decision which session would be returned for the connection. Use the getConnectedSessionToken to know the connected session.

    This can be used regardless of the session app is running or not. The controller would bind to the service while connected to wake up and keep the service process running.

Parameters
token: SessionToken

token to connect to

Returns
MediaBrowser.Builder

the Builder to allow chaining