Stay organized with collections
Save and categorize content based on your preferences.
Builder
open class Builder
Builder class for SoundPool
objects.
Summary
Public constructors |
Constructs a new Builder with the defaults format values.
|
Public constructors
Public methods
setAudioSessionId
open fun setAudioSessionId(sessionId: Int): SoundPool.Builder
Sets the session ID the SoundPool
will be attached to. Note, that if there's a device specific session id associated with the context (see Builder.setContext(Context)
), explicitly setting a session id using this method will override it.
Exceptions |
java.lang.IllegalArgumentException |
when sessionId is invalid. |
setContext
open fun setContext(context: Context): SoundPool.Builder
Sets the context the SoundPool belongs to. The context will be used to pull information, such as android.content.AttributionSource
and device specific audio session ids, which will be associated with the SoundPool
. However, the context itself will not be retained by the SoundPool
instance after initialization.
setMaxStreams
open fun setMaxStreams(maxStreams: Int): SoundPool.Builder!
Sets the maximum of number of simultaneous streams that can be played simultaneously.
Parameters |
maxStreams |
Int: a value equal to 1 or greater. |
Exceptions |
java.lang.IllegalArgumentException |
|
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.
[null,null,["Last updated 2025-02-10 UTC."],[],[],null,["# SoundPool.Builder\n\nAdded in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)\n\nBuilder\n=======\n\n*** ** * ** ***\n\nKotlin \\|[Java](/reference/android/media/SoundPool.Builder \"View this page in Java\") \n\n```\nopen class Builder\n```\n\n|---|--------------------------------------|\n| [kotlin.Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html) ||\n| ↳ | [android.media.SoundPool.Builder](#) |\n\nBuilder class for [SoundPool](/reference/kotlin/android/media/SoundPool) objects.\n\nSummary\n-------\n\n| Public constructors ||\n|-------------------------------------------------------------------------------------|---|\n| [Builder](#Builder())`()` Constructs a new Builder with the defaults format values. |\n\n| Public methods ||\n|--------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| open [SoundPool](/reference/kotlin/android/media/SoundPool)! | [build](#build())`()` \u003cbr /\u003e |\n| open [SoundPool.Builder](#)! | [setAudioAttributes](#setAudioAttributes(android.media.AudioAttributes))`(`attributes:` `[AudioAttributes](/reference/kotlin/android/media/AudioAttributes)!`)` Sets the [AudioAttributes](/reference/kotlin/android/media/AudioAttributes). |\n| open [SoundPool.Builder](#) | [setAudioSessionId](#setAudioSessionId(kotlin.Int))`(`sessionId:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`)` Sets the session ID the [SoundPool](/reference/kotlin/android/media/SoundPool) will be attached to. |\n| open [SoundPool.Builder](#) | [setContext](#setContext(android.content.Context))`(`context:` `[Context](../content/Context.html#)`)` Sets the context the SoundPool belongs to. |\n| open [SoundPool.Builder](#)! | [setMaxStreams](#setMaxStreams(kotlin.Int))`(`maxStreams:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`)` Sets the maximum of number of simultaneous streams that can be played simultaneously. |\n\nPublic constructors\n-------------------\n\n### Builder\n\nAdded in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nBuilder()\n```\n\nConstructs a new Builder with the defaults format values. If not provided, the maximum number of streams is 1 (see [setMaxStreams(int)](#setMaxStreams(kotlin.Int)) to change it), and the audio attributes have a usage value of [AudioAttributes.USAGE_MEDIA](/reference/kotlin/android/media/AudioAttributes#USAGE_MEDIA:kotlin.Int) (see [setAudioAttributes(android.media.AudioAttributes)](#setAudioAttributes(android.media.AudioAttributes)) to change them).\n\nPublic methods\n--------------\n\n### build\n\nAdded in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nopen fun build(): SoundPool!\n``` \n\n### setAudioAttributes\n\nAdded in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nopen fun setAudioAttributes(attributes: AudioAttributes!): SoundPool.Builder!\n```\n\nSets the [AudioAttributes](/reference/kotlin/android/media/AudioAttributes). For examples, game applications will use attributes built with usage information set to [AudioAttributes.USAGE_GAME](/reference/kotlin/android/media/AudioAttributes#USAGE_GAME:kotlin.Int).\n\n| Parameters ||\n|--------------|---------------------------------------------------------------------------------|\n| `attributes` | [AudioAttributes](/reference/kotlin/android/media/AudioAttributes)!: a non-null |\n\n| Return ||\n|-------------------------|---|\n| [SoundPool.Builder](#)! | |\n\n### setAudioSessionId\n\nAdded in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nopen fun setAudioSessionId(sessionId: Int): SoundPool.Builder\n```\n\nSets the session ID the [SoundPool](/reference/kotlin/android/media/SoundPool) will be attached to. Note, that if there's a device specific session id associated with the context (see [Builder.setContext(Context)](#setContext(android.content.Context))), explicitly setting a session id using this method will override it.\n\n| Parameters ||\n|-------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `sessionId` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html): a strictly positive ID number retrieved from another player or allocated by [AudioManager](/reference/kotlin/android/media/AudioManager) via [AudioManager.generateAudioSessionId()](/reference/kotlin/android/media/AudioManager#generateAudioSessionId()), or [AudioManager.AUDIO_SESSION_ID_GENERATE](/reference/kotlin/android/media/AudioManager#AUDIO_SESSION_ID_GENERATE:kotlin.Int). |\n\n| Return ||\n|------------------------|-------------------------------------------------------------|\n| [SoundPool.Builder](#) | the same [Builder](#) instance This value cannot be `null`. |\n\n| Exceptions ||\n|--------------------------------------|----------------------------|\n| `java.lang.IllegalArgumentException` | when sessionId is invalid. |\n\n### setContext\n\nAdded in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nopen fun setContext(context: Context): SoundPool.Builder\n```\n\nSets the context the SoundPool belongs to. The context will be used to pull information, such as [android.content.AttributionSource](../content/AttributionSource.html#) and device specific audio session ids, which will be associated with the [SoundPool](/reference/kotlin/android/media/SoundPool). However, the context itself will not be retained by the [SoundPool](/reference/kotlin/android/media/SoundPool) instance after initialization.\n\n| Parameters ||\n|-----------|----------------------------------------------------------------------------------------------|\n| `context` | [Context](../content/Context.html#): a non-null [Context](../content/Context.html#) instance |\n\n| Return ||\n|------------------------|--------------------------------------------------------------|\n| [SoundPool.Builder](#) | the same [Builder](#) instance. This value cannot be `null`. |\n\n### setMaxStreams\n\nAdded in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nopen fun setMaxStreams(maxStreams: Int): SoundPool.Builder!\n```\n\nSets the maximum of number of simultaneous streams that can be played simultaneously.\n\n| Parameters ||\n|--------------|------------------------------------------------------------------------------------------------------------|\n| `maxStreams` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html): a value equal to 1 or greater. |\n\n| Return ||\n|-------------------------|---------------------------|\n| [SoundPool.Builder](#)! | the same Builder instance |\n\n| Exceptions ||\n|--------------------------------------|---|\n| `java.lang.IllegalArgumentException` | |"]]