MediaBrowser.Builder


class MediaBrowser.Builder


A builder for MediaBrowser.

Summary

Public constructors

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

Creates a builder for MediaBrowser.

Public functions

ListenableFuture<MediaBrowser!>!

Builds a MediaBrowser asynchronously.

MediaBrowser.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.

MediaBrowser.Builder!

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

MediaBrowser.Builder!

Sets connection hints for the browser.

MediaBrowser.Builder!

Sets a listener for the browser.

MediaBrowser.Builder!

Sets the max number of commands the controller supports per media item.

Public constructors

Builder

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

Creates a builder for MediaBrowser.

The type of SessionToken for a browser would typically be a TYPE_LIBRARY_SERVICE but it may be other types. The detailed behavior depending on the type is described in Builder.

Parameters
context: Context!

The context.

token: SessionToken!

The token to connect to.

Public functions

buildAsync

fun buildAsync(): ListenableFuture<MediaBrowser!>!

Builds a MediaBrowser asynchronously.

The browser instance can be obtained like the following example:

MediaBrowser.Builder builder = new MediaBrowser.Builder(context, sessionToken);
ListenableFuture<MediaBrowser> future = builder.buildAsync();
future.addListener(() -> {
  try {
    MediaBrowser browser = future.get();
    // The session accepted the connection.
  } catch (ExecutionException | InterruptedException e) {
    if (e.getCause() instanceof SecurityException) {
      // The session rejected the connection.
    }
  }
}, ContextCompat.getMainExecutor(context));

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<MediaBrowser!>!

A future of the browser instance.

setApplicationLooper

@CanIgnoreReturnValue
fun setApplicationLooper(looper: Looper!): MediaBrowser.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
MediaBrowser.Builder!

The builder to allow chaining.

setBitmapLoader

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

Sets a BitmapLoader for the MediaBrowser 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
MediaBrowser.Builder!

The builder to allow chaining.

setConnectionHints

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

Sets connection hints for the browser.

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

Parameters
connectionHints: Bundle!

A bundle containing the connection hints.

Returns
MediaBrowser.Builder!

The builder to allow chaining.

setListener

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

Sets a listener for the browser.

Parameters
listener: MediaBrowser.Listener!

The listener.

Returns
MediaBrowser.Builder!

The builder to allow chaining.

setMaxCommandsForMediaItems

@UnstableApi
@CanIgnoreReturnValue
fun setMaxCommandsForMediaItems(maxCommandsForMediaItems: Int): MediaBrowser.Builder!

Sets the max number of commands the controller supports per media item.

Must be greater or equal to 0. The default is 0.

Parameters
maxCommandsForMediaItems: Int

The max number of commands per media item.

Returns
MediaBrowser.Builder!

The builder to allow chaining.