Stay organized with collections
Save and categorize content based on your preferences.
Builder
class Builder
This API is not generally intended for third party application developers. Use the AndroidX Media3 session Library for consistent behavior across all devices.
Builder for MediaController2
.
Any incoming event from the MediaSession2
will be handled on the callback executor. If it's not set, Context.getMainExecutor()
will be used by default.
Summary
Public constructors
Public methods
setConnectionHints
fun setConnectionHints(connectionHints: Bundle): MediaController2.Builder
Set the connection hints for the controller.
connectionHints
is a session-specific argument to send to the session when connecting. The contents of this bundle may affect the connection result.
An IllegalArgumentException
will be thrown if the bundle contains any non-framework Parcelable objects.
Parameters |
connectionHints |
Bundle: a bundle which contains the connection hints This value cannot be null . |
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-02-10 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-02-10 UTC."],[],[],null,["# MediaController2.Builder\n\nAdded in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)\n\nBuilder\n=======\n\n*** ** * ** ***\n\nKotlin \\|[Java](/reference/android/media/MediaController2.Builder \"View this page in Java\") \n\n```\nclass Builder\n```\n\n|---|---------------------------------------------|\n| [kotlin.Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html) ||\n| ↳ | [android.media.MediaController2.Builder](#) |\n\nThis API is not generally intended for third party application developers. Use the [AndroidX](https://developer.android.com/jetpack/androidx.html) [Media3 session Library](https://developer.android.com/media/media3/session/control-playback) for consistent behavior across all devices.\n\nBuilder for [MediaController2](/reference/kotlin/android/media/MediaController2).\n\nAny incoming event from the [MediaSession2](/reference/kotlin/android/media/MediaSession2) will be handled on the callback executor. If it's not set, [Context.getMainExecutor()](../content/Context.html#getMainExecutor()) will be used by default.\n\nSummary\n-------\n\n| Public constructors ||\n|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|\n| [Builder](#Builder(android.content.Context,%20android.media.Session2Token))`(`context:` `[Context](../content/Context.html#)`, `token:` `[Session2Token](/reference/kotlin/android/media/Session2Token)`)` Creates a builder for [MediaController2](/reference/kotlin/android/media/MediaController2). |\n\n| Public methods ||\n|----------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| [MediaController2](/reference/kotlin/android/media/MediaController2) | [build](#build())`()` Build [MediaController2](/reference/kotlin/android/media/MediaController2). |\n| [MediaController2.Builder](#) | [setConnectionHints](#setConnectionHints(android.os.Bundle))`(`connectionHints:` `[Bundle](../os/Bundle.html#)`)` Set the connection hints for the controller. |\n| [MediaController2.Builder](#) | [setControllerCallback](#setControllerCallback(java.util.concurrent.Executor,%20android.media.MediaController2.ControllerCallback))`(`executor:` `[Executor](../../java/util/concurrent/Executor.html#)`, `callback:` `[MediaController2.ControllerCallback](/reference/kotlin/android/media/MediaController2.ControllerCallback)`)` Set callback for the controller and its executor. |\n\nPublic constructors\n-------------------\n\n### Builder\n\nAdded in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nBuilder(\n context: Context, \n token: Session2Token)\n```\n\nCreates a builder for [MediaController2](/reference/kotlin/android/media/MediaController2).\n\n| Parameters ||\n|-----------|---------------------------------------------------------------------------------------------------------------------------------|\n| `context` | [Context](../content/Context.html#): context This value cannot be `null`. |\n| `token` | [Session2Token](/reference/kotlin/android/media/Session2Token): token of the session to connect to This value cannot be `null`. |\n\nPublic methods\n--------------\n\n### build\n\nAdded in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nfun build(): MediaController2\n```\n\nBuild [MediaController2](/reference/kotlin/android/media/MediaController2).\n\n| Return ||\n|----------------------------------------------------------------------|-----------------------------------------------|\n| [MediaController2](/reference/kotlin/android/media/MediaController2) | a new controller This value cannot be `null`. |\n\n### setConnectionHints\n\nAdded in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nfun setConnectionHints(connectionHints: Bundle): MediaController2.Builder\n```\n\nSet the connection hints for the controller.\n\n`connectionHints` is a session-specific argument to send to the session when connecting. The contents of this bundle may affect the connection result.\n\nAn [IllegalArgumentException](../../java/lang/IllegalArgumentException.html#) will be thrown if the bundle contains any non-framework Parcelable objects.\n\n| Parameters ||\n|-------------------|---------------------------------------------------------------------------------------------------------|\n| `connectionHints` | [Bundle](../os/Bundle.html#): a bundle which contains the connection hints This value cannot be `null`. |\n\n| Return ||\n|-------------------------------|------------------------------------------------------------|\n| [MediaController2.Builder](#) | The Builder to allow chaining This value cannot be `null`. |\n\n### setControllerCallback\n\nAdded in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nfun setControllerCallback(\n executor: Executor, \n callback: MediaController2.ControllerCallback\n): MediaController2.Builder\n```\n\nSet callback for the controller and its executor.\n\n| Parameters ||\n|------------|------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `executor` | [Executor](../../java/util/concurrent/Executor.html#): callback executor This value cannot be `null`. |\n| `callback` | [MediaController2.ControllerCallback](/reference/kotlin/android/media/MediaController2.ControllerCallback): session callback. This value cannot be `null`. |\n\n| Return ||\n|-------------------------------|------------------------------------------------------------|\n| [MediaController2.Builder](#) | The Builder to allow chaining This value cannot be `null`. |"]]