# MediaBrowser.Builder

Artifact: [androidx.media3:media3-session](https://developer.android.com/jetpack/androidx/releases/media3) [View Source](https://cs.android.com/search?q=file:androidx/media3/session/MediaBrowser.java+class:androidx.media3.session.MediaBrowser.Builder)

*** ** * ** ***


```
public final class MediaBrowser.Builder
```

<br />

*** ** * ** ***

A builder for `https://developer.android.com/reference/androidx/media3/session/MediaBrowser`.

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/media3/session/MediaBrowser.Builder#Builder(android.content.Context,androidx.media3.session.SessionToken)(https://developer.android.com/reference/android/content/Context.html context, https://developer.android.com/reference/androidx/media3/session/SessionToken token)` Creates a builder for `https://developer.android.com/reference/androidx/media3/session/MediaBrowser`. |

| ### Public methods |
|---|---|
| `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html<https://developer.android.com/reference/androidx/media3/session/MediaBrowser>` | `https://developer.android.com/reference/androidx/media3/session/MediaBrowser.Builder#buildAsync()()` Builds a `https://developer.android.com/reference/androidx/media3/session/MediaBrowser` asynchronously. |
| `https://developer.android.com/reference/androidx/media3/session/MediaBrowser.Builder` | `@https://developer.android.com/reference/androidx/media3/common/util/ExperimentalApi @https://checkerframework.org/api/com/google/errorprone/annotations/CanIgnoreReturnValue.html https://developer.android.com/reference/androidx/media3/session/MediaBrowser.Builder#experimentalSetPlatformSessionCallbackAggregationTimeoutMs(long)( long platformSessionCallbackAggregationTimeoutMs )` Sets the timeout after which updates from the platform session callbacks are applied to the browser, in milliseconds. |
| `https://developer.android.com/reference/androidx/media3/session/MediaBrowser.Builder` | `@https://developer.android.com/reference/androidx/media3/common/util/UnstableApi @https://checkerframework.org/api/com/google/errorprone/annotations/CanIgnoreReturnValue.html @https://developer.android.com/reference/androidx/media3/common/util/ExperimentalApi https://developer.android.com/reference/androidx/media3/session/MediaBrowser.Builder#setAllowDeviceVolumeCommandsForLocalPlayback(boolean)( boolean allowDeviceVolumeCommandsForLocalPlayback )` Sets whether `https://developer.android.com/reference/androidx/media3/common/Player#COMMAND_SET_DEVICE_VOLUME_WITH_FLAGS()` and `https://developer.android.com/reference/androidx/media3/common/Player#COMMAND_ADJUST_DEVICE_VOLUME_WITH_FLAGS()` are allowed to be available for `https://developer.android.com/reference/androidx/media3/common/DeviceInfo#PLAYBACK_TYPE_LOCAL()` playbacks (assuming the media session supports it). |
| `https://developer.android.com/reference/androidx/media3/session/MediaBrowser.Builder` | `@https://checkerframework.org/api/com/google/errorprone/annotations/CanIgnoreReturnValue.html https://developer.android.com/reference/androidx/media3/session/MediaBrowser.Builder#setApplicationLooper(android.os.Looper)(https://developer.android.com/reference/android/os/Looper.html looper)` Sets a `https://developer.android.com/reference/android/os/Looper.html` that must be used for all calls to the `https://developer.android.com/reference/androidx/media3/common/Player` methods and that is used to call `https://developer.android.com/reference/androidx/media3/common/Player.Listener` methods on. |
| `https://developer.android.com/reference/androidx/media3/session/MediaBrowser.Builder` | `@https://developer.android.com/reference/androidx/media3/common/util/UnstableApi @https://checkerframework.org/api/com/google/errorprone/annotations/CanIgnoreReturnValue.html https://developer.android.com/reference/androidx/media3/session/MediaBrowser.Builder#setBitmapLoader(androidx.media3.common.util.BitmapLoader)(https://developer.android.com/reference/androidx/media3/common/util/BitmapLoader bitmapLoader)` Sets a `https://developer.android.com/reference/androidx/media3/common/util/BitmapLoader` for the `https://developer.android.com/reference/androidx/media3/session/MediaBrowser` to decode bitmaps from compressed binary data. |
| `https://developer.android.com/reference/androidx/media3/session/MediaBrowser.Builder` | `@https://checkerframework.org/api/com/google/errorprone/annotations/CanIgnoreReturnValue.html https://developer.android.com/reference/androidx/media3/session/MediaBrowser.Builder#setConnectionHints(android.os.Bundle)(https://developer.android.com/reference/android/os/Bundle.html connectionHints)` Sets connection hints for the browser. |
| `https://developer.android.com/reference/androidx/media3/session/MediaBrowser.Builder` | `@https://checkerframework.org/api/com/google/errorprone/annotations/CanIgnoreReturnValue.html https://developer.android.com/reference/androidx/media3/session/MediaBrowser.Builder#setListener(androidx.media3.session.MediaBrowser.Listener)(https://developer.android.com/reference/androidx/media3/session/MediaBrowser.Listener listener)` Sets a listener for the browser. |
| `https://developer.android.com/reference/androidx/media3/session/MediaBrowser.Builder` | `@https://developer.android.com/reference/androidx/media3/common/util/UnstableApi @https://checkerframework.org/api/com/google/errorprone/annotations/CanIgnoreReturnValue.html https://developer.android.com/reference/androidx/media3/session/MediaBrowser.Builder#setMaxCommandsForMediaItems(int)(int maxCommandsForMediaItems)` Sets the max number of commands the controller supports per media item. |

## Public constructors

### Builder

```
public Builder(Context context, SessionToken token)
```

Creates a builder for `https://developer.android.com/reference/androidx/media3/session/MediaBrowser`.

The type of `https://developer.android.com/reference/androidx/media3/session/SessionToken` for a browser would typically be a `https://developer.android.com/reference/androidx/media3/session/SessionToken#TYPE_LIBRARY_SERVICE()` but it may be other types. The detailed behavior depending on the type is described in `https://developer.android.com/reference/androidx/media3/session/MediaController.Builder#Builder(android.content.Context,androidx.media3.session.SessionToken)`.

| Parameters |
|---|---|
| `https://developer.android.com/reference/android/content/Context.html context` | The context. |
| `https://developer.android.com/reference/androidx/media3/session/SessionToken token` | The token to connect to. |

## Public methods

### buildAsync

```
public ListenableFuture<MediaBrowser> buildAsync()
```

Builds a `https://developer.android.com/reference/androidx/media3/session/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 `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html#addListener(java.lang.Runnable, java.util.concurrent.Executor)` would never be called.

| Returns |
|---|---|
| `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html<https://developer.android.com/reference/androidx/media3/session/MediaBrowser>` | A future of the browser instance. |

### experimentalSetPlatformSessionCallbackAggregationTimeoutMs

```
@ExperimentalApi
@CanIgnoreReturnValue
public MediaBrowser.Builder experimentalSetPlatformSessionCallbackAggregationTimeoutMs(
    long platformSessionCallbackAggregationTimeoutMs
)
```

Sets the timeout after which updates from the platform session callbacks are applied to the browser, in milliseconds.

The default is 100ms.

| Parameters |
|---|---|
| `long platformSessionCallbackAggregationTimeoutMs` | The timeout, in milliseconds. |

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/media3/session/MediaBrowser.Builder` | The builder to allow chaining. |

### setAllowDeviceVolumeCommandsForLocalPlayback

```
@UnstableApi
@CanIgnoreReturnValue
@ExperimentalApi
public MediaBrowser.Builder setAllowDeviceVolumeCommandsForLocalPlayback(
    boolean allowDeviceVolumeCommandsForLocalPlayback
)
```

Sets whether `https://developer.android.com/reference/androidx/media3/common/Player#COMMAND_SET_DEVICE_VOLUME_WITH_FLAGS()` and `https://developer.android.com/reference/androidx/media3/common/Player#COMMAND_ADJUST_DEVICE_VOLUME_WITH_FLAGS()` are allowed to be available for `https://developer.android.com/reference/androidx/media3/common/DeviceInfo#PLAYBACK_TYPE_LOCAL()` playbacks (assuming the media session supports it).

This method will be removed in a future release.

The default is `false`. Local device volume changes should not generally be done by apps and can be triggered via `https://developer.android.com/reference/android/media/AudioManager.html` without using a media controller or media session.

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/media3/session/MediaBrowser.Builder` | The builder to allow chaining. |

### setApplicationLooper

```
@CanIgnoreReturnValue
public MediaBrowser.Builder setApplicationLooper(Looper looper)
```

Sets a `https://developer.android.com/reference/android/os/Looper.html` that must be used for all calls to the `https://developer.android.com/reference/androidx/media3/common/Player` methods and that is used to call `https://developer.android.com/reference/androidx/media3/common/Player.Listener` methods on. The `https://developer.android.com/reference/android/os/Looper.html#myLooper()` current looper} at that time this builder is created will be used if not specified. The `https://developer.android.com/reference/android/os/Looper.html#getMainLooper()` will be used if the current looper doesn't exist.

| Parameters |
|---|---|
| `https://developer.android.com/reference/android/os/Looper.html looper` | The looper. |

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/media3/session/MediaBrowser.Builder` | The builder to allow chaining. |

### setBitmapLoader

```
@UnstableApi
@CanIgnoreReturnValue
public MediaBrowser.Builder setBitmapLoader(BitmapLoader bitmapLoader)
```

Sets a `https://developer.android.com/reference/androidx/media3/common/util/BitmapLoader` for the `https://developer.android.com/reference/androidx/media3/session/MediaBrowser` to decode bitmaps from compressed binary data. If not set, a `https://developer.android.com/reference/androidx/media3/session/CacheBitmapLoader` that wraps a `https://developer.android.com/reference/androidx/media3/datasource/DataSourceBitmapLoader` will be used.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/util/BitmapLoader bitmapLoader` | The bitmap loader. |

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/media3/session/MediaBrowser.Builder` | The builder to allow chaining. |

### setConnectionHints

```
@CanIgnoreReturnValue
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 `https://developer.android.com/reference/androidx/media3/session/MediaSession`. They will be ignored when connecting to `android.support.v4.media.session.MediaSessionCompat`.

| Parameters |
|---|---|
| `https://developer.android.com/reference/android/os/Bundle.html connectionHints` | A bundle containing the connection hints. |

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/media3/session/MediaBrowser.Builder` | The builder to allow chaining. |

### setListener

```
@CanIgnoreReturnValue
public MediaBrowser.Builder setListener(MediaBrowser.Listener listener)
```

Sets a listener for the browser.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/session/MediaBrowser.Listener listener` | The listener. |

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/media3/session/MediaBrowser.Builder` | The builder to allow chaining. |

### setMaxCommandsForMediaItems

```
@UnstableApi
@CanIgnoreReturnValue
public MediaBrowser.Builder setMaxCommandsForMediaItems(int maxCommandsForMediaItems)
```

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

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

| Parameters |
|---|---|
| `int maxCommandsForMediaItems` | The max number of commands per media item. |

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/media3/session/MediaBrowser.Builder` | The builder to allow chaining. |