public final class

MediaBrowser.Builder

extends java.lang.Object

 java.lang.Object

↳androidx.media3.session.MediaBrowser.Builder

Overview

A builder for MediaBrowser.

Summary

Constructors
publicBuilder(Context context, SessionToken token)

Creates a builder for MediaBrowser.

Methods
public <any>buildAsync()

Builds a MediaBrowser asynchronously.

public MediaBrowser.BuildersetApplicationLooper(Looper looper)

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

public MediaBrowser.BuildersetConnectionHints(Bundle connectionHints)

Sets connection hints for the browser.

public MediaBrowser.BuildersetListener(MediaBrowser.Listener listener)

Sets a listener for the browser.

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

Constructors

public Builder(Context context, SessionToken token)

Creates a builder for MediaBrowser.

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

Parameters:

context: The context.
token: The token to connect to.

Methods

public MediaBrowser.Builder setConnectionHints(Bundle connectionHints)

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: A bundle containing the connection hints.

Returns:

The builder to allow chaining.

public MediaBrowser.Builder setListener(MediaBrowser.Listener listener)

Sets a listener for the browser.

Parameters:

listener: The listener.

Returns:

The builder to allow chaining.

public MediaBrowser.Builder setApplicationLooper(Looper looper)

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

Parameters:

looper: The looper.

Returns:

The builder to allow chaining.

public <any> buildAsync()

Builds a MediaBrowser asynchronously.

The browser instance can be obtained like the following example:

 MediaBrowser.Builder builder = ...;
 ListenableFuture future = builder.buildAsync();
 future.addListener(() -> {
   try {
     MediaBrowser browser = 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 would never be called.

Returns:

A future of the browser instance.