# SoundEffectPoolComponent

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/SoundEffectPoolComponent.kt+class:androidx.xr.scenecore.SoundEffectPoolComponent) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-scenecore#1.0.0)

*** ** * ** ***


```
class SoundEffectPoolComponent : Component, SoundEffectPlayer
```

<br />

|---|---|---|
| [kotlin.Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html) |||
| ↳ | [androidx.xr.scenecore.Component](https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Component) ||
|   | ↳ | [androidx.xr.scenecore.SoundEffectPoolComponent](https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SoundEffectPoolComponent) |

*** ** * ** ***

Provides positional sound pool audio playback for an `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity`.

This component provides a method to play short sounds loaded by a `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SoundEffectPool`. The audio is spatialized based on the `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity`'s transform and the provided `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/PointSourceParams`.

This component can only be attached to one `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity` at a time. If the component is detached from an `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity`, the audio will become head-locked until re-attached.

## Summary

| ### Public companion functions |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SoundEffectPoolComponent` | `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SoundEffectPoolComponent#create(androidx.xr.runtime.Session,androidx.xr.scenecore.SoundEffectPool,androidx.xr.scenecore.PointSourceParams)( session: https://developer.android.com/reference/kotlin/androidx/xr/runtime/Session, soundEffectPool: https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SoundEffectPool, params: https://developer.android.com/reference/kotlin/androidx/xr/scenecore/PointSourceParams )` Creates a `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SoundEffectPoolComponent`. |

| ### Public functions |
|---|---|
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SoundEffectPoolComponent#pause(androidx.xr.scenecore.Stream)(stream: https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Stream)` Pauses a currently playing sound stream. |
| `open https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Stream` | `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SoundEffectPoolComponent#play(androidx.xr.scenecore.SoundEffect,kotlin.Float,kotlin.Int,kotlin.Boolean)( soundEffect: https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SoundEffect, volume: @https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = 0.0, to = 1.0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html, priority: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, isLooping: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html )` Plays a loaded sound effect. |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SoundEffectPoolComponent#resume(androidx.xr.scenecore.Stream)(stream: https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Stream)` Resumes a previously paused sound stream. |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SoundEffectPoolComponent#setLooping(androidx.xr.scenecore.Stream,kotlin.Boolean)(stream: https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Stream, isLooping: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)` Updates the looping status of an active stream. |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SoundEffectPoolComponent#setVolume(androidx.xr.scenecore.Stream,kotlin.Float)(stream: https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Stream, volume: @https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = 0.0, to = 1.0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html)` Updates the volume of an active stream. |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SoundEffectPoolComponent#stop(androidx.xr.scenecore.Stream)(stream: https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Stream)` Stops a currently playing or paused sound stream and releases that stream ID. |

| ### Protected functions |
|---|---|
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SoundEffectPoolComponent#onAttach(androidx.xr.scenecore.Entity)(entity: https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity)` Called by the framework when this component is being added to an `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity`. |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SoundEffectPoolComponent#onDetach(androidx.xr.scenecore.Entity)(entity: https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity)` Called by the framework when this component is being removed from an `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity`. |

| ### Public properties |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/PointSourceParams` | `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SoundEffectPoolComponent#pointSourceParams()` Updates the `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/PointSourceParams` used by the spatial audio source. |

| ### Extension functions |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/xr/compose/subspace/media/SpatializedAudioOutput` | `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SoundEffectPoolComponent.https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SoundEffectPoolComponent#(androidx.xr.scenecore.SoundEffectPoolComponent).asSpatializedAudioOutput()()` Returns a `https://developer.android.com/reference/kotlin/androidx/xr/compose/subspace/media/SpatializedAudioOutput` that wraps this `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SoundEffectPoolComponent`. |

## 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,
    soundEffectPool: SoundEffectPool,
    params: PointSourceParams
): SoundEffectPoolComponent
```

Creates a `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SoundEffectPoolComponent`.

| Parameters |
|---|---|
| `session: https://developer.android.com/reference/kotlin/androidx/xr/runtime/Session` | the active XR session |
| `soundEffectPool: https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SoundEffectPool` | pool that manages the loaded sound assets |
| `params: https://developer.android.com/reference/kotlin/androidx/xr/scenecore/PointSourceParams` | initial spatial audio parameters for this source |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SoundEffectPoolComponent` | new instance of `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SoundEffectPoolComponent` |

## Public functions

### pause

```
open fun pause(stream: Stream): Unit
```

Pauses a currently playing sound stream.

If the `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SoundEffectPlayer#pause(androidx.xr.scenecore.Stream)` has already been stopped or released due to hitting the max stream count then this method has no effect.

| Parameters |
|---|---|
| `stream: https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Stream` | a `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Stream` returned by `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SoundEffectPlayer#play(androidx.xr.scenecore.SoundEffect,kotlin.Float,kotlin.Int,kotlin.Boolean)` |

### play

```
open fun play(
    soundEffect: SoundEffect,
    volume: @FloatRange(from = 0.0, to = 1.0) Float,
    priority: @IntRange(from = 0) Int,
    isLooping: Boolean
): Stream
```

Plays a loaded sound effect.

The `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SoundEffect`s can play concurrently up to the max stream count of the `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SoundEffectPool` from which they were loaded. If the max stream count is exceeded, streams with lower priority are stopped first.

| Parameters |
|---|---|
| `soundEffect: https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SoundEffect` | the handle to the loaded `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SoundEffect` to play |
| `volume: @https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = 0.0, to = 1.0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | volume in the range 0.0 to 1.0 |
| `priority: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | playback priority (0 = lowest) |
| `isLooping: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | true to loop indefinitely, false to play once |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Stream` | a `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Stream` for controlling this specific instance of the sound |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-runtime-exception/index.html` | if the sound effect fails to play |

### resume

```
open fun resume(stream: Stream): Unit
```

Resumes a previously paused sound stream.

If the `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SoundEffectPlayer#resume(androidx.xr.scenecore.Stream)` has already been stopped or released due to hitting the max stream count then this method has no effect.

| Parameters |
|---|---|
| `stream: https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Stream` | a `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Stream` returned by `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SoundEffectPlayer#play(androidx.xr.scenecore.SoundEffect,kotlin.Float,kotlin.Int,kotlin.Boolean)` |

### setLooping

```
open fun setLooping(stream: Stream, isLooping: Boolean): Unit
```

Updates the looping status of an active stream.

If the `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SoundEffectPlayer#setLooping(androidx.xr.scenecore.Stream,kotlin.Boolean)` has already been stopped or released due to hitting the max stream count then this method has no effect.

| Parameters |
|---|---|
| `stream: https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Stream` | a `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Stream` returned by `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SoundEffectPlayer#play(androidx.xr.scenecore.SoundEffect,kotlin.Float,kotlin.Int,kotlin.Boolean)` |
| `isLooping: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | true to loop indefinitely, false to stop looping |

### setVolume

```
open fun setVolume(stream: Stream, volume: @FloatRange(from = 0.0, to = 1.0) Float): Unit
```

Updates the volume of an active stream.

If the `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SoundEffectPlayer#setVolume(androidx.xr.scenecore.Stream,kotlin.Float)` has already been stopped or released due to hitting the max stream count then this method has no effect.

| Parameters |
|---|---|
| `stream: https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Stream` | a `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Stream` returned by `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SoundEffectPlayer#play(androidx.xr.scenecore.SoundEffect,kotlin.Float,kotlin.Int,kotlin.Boolean)` |
| `volume: @https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = 0.0, to = 1.0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | volume in the range 0.0 to 1.0 |

### stop

```
open fun stop(stream: Stream): Unit
```

Stops a currently playing or paused sound stream and releases that stream ID.

If the `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SoundEffectPlayer#stop(androidx.xr.scenecore.Stream)` has already been stopped or released due to hitting the max stream count then this method has no effect.

| Parameters |
|---|---|
| `stream: https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Stream` | a `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Stream` returned by `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SoundEffectPlayer#play(androidx.xr.scenecore.SoundEffect,kotlin.Float,kotlin.Int,kotlin.Boolean)` |

## Protected functions

### onAttach

```
protected open fun onAttach(entity: Entity): Boolean
```

Called by the framework when this component is being added to an `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity`.

This method is triggered when `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity#addComponent(androidx.xr.scenecore.Component)` is invoked. Implementations should override this method to perform setup logic or to validate if the component is compatible with the provided `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Component#onAttach(androidx.xr.scenecore.Entity)`.

| Parameters |
|---|---|
| `entity: https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity` | The `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity` to which this component is being attached. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `true` if the component was successfully attached; `false` if the `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Component#onAttach(androidx.xr.scenecore.Entity)` does not support this component or if attachment failed. |

### onDetach

```
protected open fun onDetach(entity: Entity): Unit
```

Called by the framework when this component is being removed from an `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity`.

This method is triggered when `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity#removeComponent(androidx.xr.scenecore.Component)` is invoked. Implementations should override this method to release resources or undo any changes made during `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Component#onAttach(androidx.xr.scenecore.Entity)`.

| Parameters |
|---|---|
| `entity: https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity` | The `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity` from which this component is being detached. |

## Public properties

### pointSourceParams

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

```
var pointSourceParams: PointSourceParams
```

Updates the `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/PointSourceParams` used by the spatial audio source.

These pointSourceParams will apply to future playback requests.

## Extension functions

### SoundEffectPoolComponent.asSpatializedAudioOutput

Artifact: [androidx.xr.compose:compose](https://developer.android.com/jetpack/androidx/releases/xr-compose) [View Source](https://cs.android.com/search?q=file:androidx/xr/compose/subspace/media/SpatializedAudioOutput.kt+function:asSpatializedAudioOutput)

```
fun SoundEffectPoolComponent.asSpatializedAudioOutput(): SpatializedAudioOutput
```

Returns a `https://developer.android.com/reference/kotlin/androidx/xr/compose/subspace/media/SpatializedAudioOutput` that wraps this `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SoundEffectPoolComponent`. This allows the component's audio to be spatialized from the Composable it is attached to via `https://developer.android.com/reference/kotlin/androidx/xr/compose/subspace/media/package-summary#(androidx.xr.compose.subspace.layout.SubspaceModifier).spatializedAudioOutput(androidx.xr.compose.subspace.media.SpatializedAudioOutput)`.