public final class

MediaController.Builder

extends androidx.media2.session.MediaController.BuilderBase<MediaController, MediaController.Builder, MediaController.ControllerCallback>

 java.lang.Object

↳androidx.media2.session.MediaController.BuilderBase<MediaController, MediaController.Builder, MediaController.ControllerCallback>

↳androidx.media2.session.MediaController.Builder

Overview

Builder for MediaController.

To set the token of the session for the controller to connect to, one of the MediaController.Builder.setSessionToken(SessionToken) or MediaController.Builder.setSessionCompatToken(MediaSessionCompat.Token) should be called. Otherwise, the MediaController.Builder.build() will throw an java.lang.IllegalArgumentException.

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

Summary

Constructors
publicBuilder(Context context)

Methods
public MediaControllerbuild()

Builds a MediaController.

public androidx.media2.session.MediaController.BuilderBase<T, U, C>setConnectionHints(Bundle connectionHints)

Sets the connection hints for the controller.

androidx.media2.session.MediaController.BuilderBase<T, U, C>setControllerCallback(java.util.concurrent.Executor executor, MediaController.ControllerCallback callback)

Sets the callback for the controller and its executor.

androidx.media2.session.MediaController.BuilderBase<T, U, C>setSessionCompatToken(android.support.v4.media.session.MediaSessionCompat.Token compatToken)

Sets the for the controller to connect to.

androidx.media2.session.MediaController.BuilderBase<T, U, C>setSessionToken(SessionToken token)

Sets the SessionToken for the controller to connect to.

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

Constructors

public Builder(Context context)

Methods

androidx.media2.session.MediaController.BuilderBase<T, U, C> setSessionToken(SessionToken token)

Sets the SessionToken for the controller to connect to.

When this method is called, the 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 SessionToken.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 SessionToken.TYPE_SESSION_SERVICE or SessionToken.TYPE_LIBRARY_SERVICE

    The controller connects to the session provided by the MediaSessionService. It's up to the service's decision which session would be returned for the connection. Use the androidx.media2.session.MediaController.BuilderBase 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: token to connect to

Returns:

the Builder to allow chaining

See also: MediaSessionService, androidx.media2.session.MediaController.BuilderBase, setConnectionHints

androidx.media2.session.MediaController.BuilderBase<T, U, C> setSessionCompatToken(android.support.v4.media.session.MediaSessionCompat.Token compatToken)

Sets the for the controller to connect to.

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

Parameters:

compatToken: token to connect to

Returns:

the Builder to allow chaining

public androidx.media2.session.MediaController.BuilderBase<T, U, C> setConnectionHints(Bundle connectionHints)

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 android.support.v4.media.session.MediaSessionCompat.

Parameters:

connectionHints: a bundle which contains the connection hints

Returns:

the Builder to allow chaining

androidx.media2.session.MediaController.BuilderBase<T, U, C> setControllerCallback(java.util.concurrent.Executor executor, MediaController.ControllerCallback callback)

Sets the callback for the controller and its executor.

Parameters:

executor: callback executor
callback: controller callback.

Returns:

the Builder to allow chaining

public MediaController build()

Builds a MediaController.

Returns:

a new controller