# 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)

*** ** * ** ***


```
class MediaBrowser.Builder
```

<br />

*** ** * ** ***

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

## Summary

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

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

## Public constructors

### Builder

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

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

The type of `https://developer.android.com/reference/kotlin/androidx/media3/session/SessionToken` for a browser would typically be a `https://developer.android.com/reference/kotlin/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/kotlin/androidx/media3/session/MediaController.Builder#Builder(android.content.Context,androidx.media3.session.SessionToken)`.

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

## Public functions

### buildAsync

```
fun buildAsync(): ListenableFuture<MediaBrowser!>!
```

Builds a `https://developer.android.com/reference/kotlin/androidx/media3/session/MediaBrowser` asynchronously.

The browser instance can be obtained like the following example:

```kotlin
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/kotlin/androidx/media3/session/MediaBrowser!>!` | A future of the browser instance. |

### experimentalSetPlatformSessionCallbackAggregationTimeoutMs

```
@ExperimentalApi
@CanIgnoreReturnValue
fun experimentalSetPlatformSessionCallbackAggregationTimeoutMs(
    platformSessionCallbackAggregationTimeoutMs: Long
): MediaBrowser.Builder!
```

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

The default is 100ms.

| Parameters |
|---|---|
| `platformSessionCallbackAggregationTimeoutMs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | The timeout, in milliseconds. |

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

### setAllowDeviceVolumeCommandsForLocalPlayback

```
@UnstableApi
@CanIgnoreReturnValue
@ExperimentalApi
fun setAllowDeviceVolumeCommandsForLocalPlayback(
    allowDeviceVolumeCommandsForLocalPlayback: Boolean
): MediaBrowser.Builder!
```

Sets whether `https://developer.android.com/reference/kotlin/androidx/media3/common/Player#COMMAND_SET_DEVICE_VOLUME_WITH_FLAGS()` and `https://developer.android.com/reference/kotlin/androidx/media3/common/Player#COMMAND_ADJUST_DEVICE_VOLUME_WITH_FLAGS()` are allowed to be available for `https://developer.android.com/reference/kotlin/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/kotlin/androidx/media3/session/MediaBrowser.Builder!` | The builder to allow chaining. |

### setApplicationLooper

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

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/kotlin/androidx/media3/common/Player` methods and that is used to call `https://developer.android.com/reference/kotlin/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 |
|---|---|
| `looper: https://developer.android.com/reference/android/os/Looper.html!` | The looper. |

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

### setBitmapLoader

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

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

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

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

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

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

### setListener

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

Sets a listener for the browser.

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

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/session/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: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The max number of commands per media item. |

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