# SoundPool.Builder

Added in[API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

# Builder

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/android/media/SoundPool.Builder "View this page in Java")  

```
open class Builder
```

|---|--------------------------------------------------------------------------------------------------------------------|
| [kotlin.Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)                                     ||
| ↳ | [android.media.SoundPool.Builder](https://developer.android.com/reference/kotlin/android/media/SoundPool.Builder#) |

Builder class for[SoundPool](https://developer.android.com/reference/kotlin/android/media/SoundPool)objects.

## Summary

|                                                                         Public constructors                                                                          ||
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| [Builder](https://developer.android.com/reference/kotlin/android/media/SoundPool.Builder#Builder())`()` Constructs a new Builder with the defaults format values. |

|                                                                                                                                                                                                                                         Public methods                                                                                                                                                                                                                                         ||
|-----------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| open[SoundPool](https://developer.android.com/reference/kotlin/android/media/SoundPool)!                  | [build](https://developer.android.com/reference/kotlin/android/media/SoundPool.Builder#build())`()` <br />                                                                                                                                                                                                                                                                          |
| open[SoundPool.Builder](https://developer.android.com/reference/kotlin/android/media/SoundPool.Builder#)! | [setAudioAttributes](https://developer.android.com/reference/kotlin/android/media/SoundPool.Builder#setAudioAttributes(android.media.AudioAttributes))`(`attributes:` `[AudioAttributes](https://developer.android.com/reference/kotlin/android/media/AudioAttributes)!`)` Sets the[AudioAttributes](https://developer.android.com/reference/kotlin/android/media/AudioAttributes). |
| open[SoundPool.Builder](https://developer.android.com/reference/kotlin/android/media/SoundPool.Builder#)  | [setAudioSessionId](https://developer.android.com/reference/kotlin/android/media/SoundPool.Builder#setAudioSessionId(kotlin.Int))`(`sessionId:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`)` Sets the session ID the[SoundPool](https://developer.android.com/reference/kotlin/android/media/SoundPool)will be attached to.                       |
| open[SoundPool.Builder](https://developer.android.com/reference/kotlin/android/media/SoundPool.Builder#)  | [setContext](https://developer.android.com/reference/kotlin/android/media/SoundPool.Builder#setContext(android.content.Context))`(`context:` `[Context](https://developer.android.com/reference/kotlin/android/content/Context.html#)`)` Sets the context the SoundPool belongs to.                                                                                                 |
| open[SoundPool.Builder](https://developer.android.com/reference/kotlin/android/media/SoundPool.Builder#)! | [setMaxStreams](https://developer.android.com/reference/kotlin/android/media/SoundPool.Builder#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.                                                                       |

## Public constructors

### Builder

Added in[API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
Builder()
```

Constructs a new Builder with the defaults format values. If not provided, the maximum number of streams is 1 (see[setMaxStreams(int)](https://developer.android.com/reference/kotlin/android/media/SoundPool.Builder#setMaxStreams(kotlin.Int))to change it), and the audio attributes have a usage value of[AudioAttributes.USAGE_MEDIA](https://developer.android.com/reference/kotlin/android/media/AudioAttributes#USAGE_MEDIA:kotlin.Int)(see[setAudioAttributes(android.media.AudioAttributes)](https://developer.android.com/reference/kotlin/android/media/SoundPool.Builder#setAudioAttributes(android.media.AudioAttributes))to change them).

## Public methods

### build

Added in[API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
open fun build(): SoundPool!
```  

### setAudioAttributes

Added in[API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
open fun setAudioAttributes(attributes: AudioAttributes!): SoundPool.Builder!
```

Sets the[AudioAttributes](https://developer.android.com/reference/kotlin/android/media/AudioAttributes). For examples, game applications will use attributes built with usage information set to[AudioAttributes.USAGE_GAME](https://developer.android.com/reference/kotlin/android/media/AudioAttributes#USAGE_GAME:kotlin.Int).

|                                                        Parameters                                                         ||
|--------------|-------------------------------------------------------------------------------------------------------------|
| `attributes` | [AudioAttributes](https://developer.android.com/reference/kotlin/android/media/AudioAttributes)!:a non-null |

|                                                  Return                                                  ||
|-------------------------------------------------------------------------------------------------------|---|
| [SoundPool.Builder](https://developer.android.com/reference/kotlin/android/media/SoundPool.Builder#)! |   |

### setAudioSessionId

Added in[API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
open fun setAudioSessionId(sessionId: Int): SoundPool.Builder
```

Sets the session ID the[SoundPool](https://developer.android.com/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)](https://developer.android.com/reference/kotlin/android/media/SoundPool.Builder#setContext(android.content.Context))), explicitly setting a session id using this method will override it.

|                                                                                                                                                                                                                                                                               Parameters                                                                                                                                                                                                                                                                                ||
|-------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `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](https://developer.android.com/reference/kotlin/android/media/AudioManager)via[AudioManager.generateAudioSessionId()](https://developer.android.com/reference/kotlin/android/media/AudioManager#generateAudioSessionId()), or[AudioManager.AUDIO_SESSION_ID_GENERATE](https://developer.android.com/reference/kotlin/android/media/AudioManager#AUDIO_SESSION_ID_GENERATE:kotlin.Int). |

|                                                                                                                    Return                                                                                                                    ||
|------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------|
| [SoundPool.Builder](https://developer.android.com/reference/kotlin/android/media/SoundPool.Builder#) | the same[Builder](https://developer.android.com/reference/kotlin/android/media/SoundPool.Builder#)instance This value cannot be`null`. |

|                            Exceptions                            ||
|--------------------------------------|----------------------------|
| `java.lang.IllegalArgumentException` | when sessionId is invalid. |

### setContext

Added in[API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
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](https://developer.android.com/reference/kotlin/android/content/AttributionSource.html#)and device specific audio session ids, which will be associated with the[SoundPool](https://developer.android.com/reference/kotlin/android/media/SoundPool). However, the context itself will not be retained by the[SoundPool](https://developer.android.com/reference/kotlin/android/media/SoundPool)instance after initialization.

|                                                                                                  Parameters                                                                                                  ||
|-----------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `context` | [Context](https://developer.android.com/reference/kotlin/android/content/Context.html#):a non-null[Context](https://developer.android.com/reference/kotlin/android/content/Context.html#)instance |

|                                                                                                                    Return                                                                                                                     ||
|------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------|
| [SoundPool.Builder](https://developer.android.com/reference/kotlin/android/media/SoundPool.Builder#) | the same[Builder](https://developer.android.com/reference/kotlin/android/media/SoundPool.Builder#)instance. This value cannot be`null`. |

### setMaxStreams

Added in[API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
open fun setMaxStreams(maxStreams: Int): SoundPool.Builder!
```

Sets the maximum of number of simultaneous streams that can be played simultaneously.

|                                                       Parameters                                                        ||
|--------------|-----------------------------------------------------------------------------------------------------------|
| `maxStreams` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html):a value equal to 1 or greater. |

|                                                              Return                                                              ||
|-------------------------------------------------------------------------------------------------------|---------------------------|
| [SoundPool.Builder](https://developer.android.com/reference/kotlin/android/media/SoundPool.Builder#)! | the same Builder instance |

|               Exceptions                ||
|--------------------------------------|---|
| `java.lang.IllegalArgumentException` |   |