# SoundEffectPool

Artifact: [androidx.xr.scenecore:scenecore](https://developer.android.com/jetpack/androidx/releases/xr-scenecore) [View Source](https://cs.android.com/search?q=file:androidx/xr/scenecore/SoundEffectPool.kt+class:androidx.xr.scenecore.SoundEffectPool) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-scenecore#1.0.0)

*** ** * ** ***


```
class SoundEffectPool : AutoCloseable
```

<br />

*** ** * ** ***

Manages the loading and unloading of sound assets into memory.

If the value of the `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SoundEffectPool#(androidx.xr.scenecore.runtime.SceneRuntime,kotlin.Int)` parameter exceeds the capabilities for the platform then the value will be clamped to the platform's max number of supported streams.

## Summary

| ### Nested types |
|---|
| `fun interface https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SoundEffectPool.LoadCompleteListener` Callback interface for receiving notification when a sound effect has finished loading. |

| ### Public companion functions |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SoundEffectPool` | `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SoundEffectPool#create(androidx.xr.runtime.Session,kotlin.Int)(session: https://developer.android.com/reference/kotlin/androidx/xr/runtime/Session, maxStreams: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Creates a `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SoundEffectPool` with the given `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SoundEffectPool.Companion#create(androidx.xr.runtime.Session,kotlin.Int)` and `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SoundEffectPool.Companion#create(androidx.xr.runtime.Session,kotlin.Int)`. |

| ### Public functions |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SoundEffectPool#addLoadCompleteListener(androidx.xr.scenecore.SoundEffectPool.LoadCompleteListener)(listener: https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SoundEffectPool.LoadCompleteListener)` Adds a listener to be invoked when sounds finish loading. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SoundEffectPool#addLoadCompleteListener(java.util.concurrent.Executor,androidx.xr.scenecore.SoundEffectPool.LoadCompleteListener)( executor: https://developer.android.com/reference/java/util/concurrent/Executor.html, listener: https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SoundEffectPool.LoadCompleteListener )` Adds a listener to be invoked when sounds finish loading. |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SoundEffectPool#close()()` |
| `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SoundEffect` | `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SoundEffectPool#load(android.content.res.AssetFileDescriptor)(assetFileDescriptor: https://developer.android.com/reference/android/content/res/AssetFileDescriptor.html)` Loads a sound from an `https://developer.android.com/reference/android/content/res/AssetFileDescriptor.html` and returns a `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SoundEffect` handle. |
| `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SoundEffect` | `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SoundEffectPool#load(android.content.Context,kotlin.Int)(context: https://developer.android.com/reference/android/content/Context.html, resId: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Loads a sound from an application resource and returns a `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SoundEffect` handle. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SoundEffectPool#release()()` Releases all native resources associated with this pool. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SoundEffectPool#removeLoadCompleteListener(androidx.xr.scenecore.SoundEffectPool.LoadCompleteListener)( listener: https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SoundEffectPool.LoadCompleteListener )` Removes a listener previously added via `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SoundEffectPool#addLoadCompleteListener(androidx.xr.scenecore.SoundEffectPool.LoadCompleteListener)` |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SoundEffectPool#unload(androidx.xr.scenecore.SoundEffect)(soundEffect: https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SoundEffect)` Unloads a sound from memory to release resources. |

## Public companion functions

### create

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-scenecore#1.0.0)

```
fun create(session: Session, maxStreams: Int): SoundEffectPool
```

Creates a `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SoundEffectPool` with the given `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SoundEffectPool.Companion#create(androidx.xr.runtime.Session,kotlin.Int)` and `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SoundEffectPool.Companion#create(androidx.xr.runtime.Session,kotlin.Int)`.

If the value of the `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SoundEffectPool.Companion#create(androidx.xr.runtime.Session,kotlin.Int)` parameter exceeds the capabilities for the platform then the value will be clamped to the platform's max number of supported streams.

| Parameters |
|---|---|
| `session: https://developer.android.com/reference/kotlin/androidx/xr/runtime/Session` | the XR session associated with this sound effect pool |
| `maxStreams: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | maximum number of simultaneous streams that can be played by this pool |

## Public functions

### addLoadCompleteListener

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-scenecore#1.0.0)

```
fun addLoadCompleteListener(listener: SoundEffectPool.LoadCompleteListener): Unit
```

Adds a listener to be invoked when sounds finish loading. The listener will be called on the main thread.

### addLoadCompleteListener

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-scenecore#1.0.0)

```
fun addLoadCompleteListener(
    executor: Executor,
    listener: SoundEffectPool.LoadCompleteListener
): Unit
```

Adds a listener to be invoked when sounds finish loading. The listener will be called on the given `https://developer.android.com/reference/java/util/concurrent/Executor.html`.

| Parameters |
|---|---|
| `executor: https://developer.android.com/reference/java/util/concurrent/Executor.html` | The `https://developer.android.com/reference/java/util/concurrent/Executor.html` to run the listener on. |
| `listener: https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SoundEffectPool.LoadCompleteListener` | The `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SoundEffectPool.LoadCompleteListener` to be invoked asynchronously on the given executor. |

### close

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-scenecore#1.0.0)

```
open fun close(): Unit
```

### load

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-scenecore#1.0.0)

```
fun load(assetFileDescriptor: AssetFileDescriptor): SoundEffect
```

Loads a sound from an `https://developer.android.com/reference/android/content/res/AssetFileDescriptor.html` and returns a `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SoundEffect` handle.

Note: Loading is asynchronous. The sound may not be ready to play immediately after this method returns. Use `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SoundEffectPool.LoadCompleteListener` to be notified when it is ready.

| Parameters |
|---|---|
| `assetFileDescriptor: https://developer.android.com/reference/android/content/res/AssetFileDescriptor.html` | the `https://developer.android.com/reference/android/content/res/AssetFileDescriptor.html` for the sound file |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SoundEffect` | a `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SoundEffect` handle for the loaded sound |

### load

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-scenecore#1.0.0)

```
fun load(context: Context, resId: Int): SoundEffect
```

Loads a sound from an application resource and returns a `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SoundEffect` handle.

Note: Loading is asynchronous. The sound may not be ready to play immediately after this method returns. Use `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SoundEffectPool.LoadCompleteListener` to be notified when it is ready.

| Parameters |
|---|---|
| `context: https://developer.android.com/reference/android/content/Context.html` | the application context |
| `resId: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | resource ID of the sound (e.g., R.raw.sound) |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SoundEffect` | a `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SoundEffect` handle for the loaded sound |

### release

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-scenecore#1.0.0)

```
fun release(): Unit
```

Releases all native resources associated with this pool.

### removeLoadCompleteListener

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-scenecore#1.0.0)

```
fun removeLoadCompleteListener(
    listener: SoundEffectPool.LoadCompleteListener
): Unit
```

Removes a listener previously added via `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SoundEffectPool#addLoadCompleteListener(androidx.xr.scenecore.SoundEffectPool.LoadCompleteListener)`

### unload

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-scenecore#1.0.0)

```
fun unload(soundEffect: SoundEffect): Boolean
```

Unloads a sound from memory to release resources.

| Parameters |
|---|---|
| `soundEffect: https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SoundEffect` | the `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SoundEffect` to unload |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | true if the sound was successfully unloaded |