MediaController.Builder


class MediaController.Builder


A builder for MediaController.

Summary

Public constructors

Builder(context: Context!, token: SessionToken!)

Creates a builder for MediaController.

Public functions

ListenableFuture<MediaController!>!

Builds a MediaController asynchronously.

MediaController.Builder!

Sets a Looper that must be used for all calls to the Player methods and that is used to call Player.Listener methods on.

MediaController.Builder!

Sets a BitmapLoader for the MediaController to decode bitmaps from compressed binary data.

MediaController.Builder!

Sets connection hints for the controller.

MediaController.Builder!

Sets a listener for the controller.

Public constructors

Builder

Builder(context: Context!, token: SessionToken!)

Creates a builder for MediaController.

The detailed behavior of the MediaController differs depending on the type of the token as follows.

  1. TYPE_SESSION: The controller connects to the specified session directly. It's recommended when you're sure which session to control, or you've got a 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. TYPE_SESSION_SERVICE or TYPE_LIBRARY_SERVICE: The controller connects to the session provided by the onGetSession or onGetSession. It's up to the service to decide which session should be returned for the connection. Use the getConnectedToken to know the connected session. This can be used regardless of whether the session app is running or not. The controller will bind to the service as long as it's connected to wake up and keep the service process running.
Parameters
context: Context!

The context.

token: SessionToken!

The token to connect to.

Public functions

buildAsync

fun buildAsync(): ListenableFuture<MediaController!>!

Builds a MediaController asynchronously.

The controller instance can be obtained like the following example:

MediaController.Builder builder = ...;
ListenableFuture<MediaController> future = builder.buildAsync();
future.addListener(() -> {
  try {
    MediaController controller = future.get();
    // The session accepted the connection.
  } catch (ExecutionException e) {
    if (e.getCause() instanceof SecurityException) {
      // The session rejected the connection.
    }
  }
}, ContextCompat.getMainExecutor());

The future must be kept by callers until the future is complete to get the controller instance. Otherwise, the future might be garbage collected and the listener added by addListener would never be called.

Returns
ListenableFuture<MediaController!>!

A future of the controller instance.

setApplicationLooper

@CanIgnoreReturnValue
fun setApplicationLooper(looper: Looper!): MediaController.Builder!

Sets a Looper that must be used for all calls to the Player methods and that is used to call Player.Listener methods on. The myLooper current looper} at that time this builder is created will be used if not specified. The main looper will be used if the current looper doesn't exist.

Parameters
looper: Looper!

The looper.

Returns
MediaController.Builder!

The builder to allow chaining.

setBitmapLoader

@UnstableApi
@CanIgnoreReturnValue
fun setBitmapLoader(bitmapLoader: BitmapLoader!): MediaController.Builder!

Sets a BitmapLoader for the MediaController to decode bitmaps from compressed binary data. If not set, a CacheBitmapLoader that wraps a will be used.

Parameters
bitmapLoader: BitmapLoader!

The bitmap loader.

Returns
MediaController.Builder!

The builder to allow chaining.

setConnectionHints

@CanIgnoreReturnValue
fun setConnectionHints(connectionHints: Bundle!): MediaController.Builder!

Sets connection hints for the controller.

The hints are session-specific arguments sent to the session when connecting. The contents of this bundle may affect the connection result.

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

Parameters
connectionHints: Bundle!

A bundle containing the connection hints.

Returns
MediaController.Builder!

The builder to allow chaining.

setListener

@CanIgnoreReturnValue
fun setListener(listener: MediaController.Listener!): MediaController.Builder!

Sets a listener for the controller.

Parameters
listener: MediaController.Listener!

The listener.

Returns
MediaController.Builder!

The builder to allow chaining.