MediaController.Builder

Added in 1.0.0
Deprecated in 1.3.0

class MediaController.Builder


Builder for MediaController.

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

MediaController

Builds a MediaController.

MediaController.Builder
setConnectionHints(connectionHints: Bundle)

Sets the connection hints for the controller.

MediaController.Builder

Sets the callback for the controller and its executor.

MediaController.Builder

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

MediaController.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(): MediaController

Builds a MediaController.

Returns
MediaController

a new controller

setConnectionHints

Added in 1.0.0
Deprecated in 1.3.0
fun setConnectionHints(connectionHints: Bundle): MediaController.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
MediaController.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: MediaController.ControllerCallback
): MediaController.Builder

Sets the callback for the controller and its executor.

Parameters
executor: Executor

callback executor

callback: MediaController.ControllerCallback

controller callback.

Returns
MediaController.Builder

the Builder to allow chaining

setSessionCompatToken

Added in 1.0.0
Deprecated in 1.3.0
fun setSessionCompatToken(compatToken: MediaSessionCompat.Token): MediaController.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
MediaController.Builder

the Builder to allow chaining

setSessionToken

Added in 1.0.0
Deprecated in 1.3.0
fun setSessionToken(token: SessionToken): MediaController.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
MediaController.Builder

the Builder to allow chaining