# 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)

*** ** * ** ***


```
public final class SoundEffectPoolComponent extends Component implements SoundEffectPlayer
```

<br />

|---|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object.html) |||
| ↳ | [androidx.xr.scenecore.Component](https://developer.android.com/reference/androidx/xr/scenecore/Component) ||
|   | ↳ | [androidx.xr.scenecore.SoundEffectPoolComponent](https://developer.android.com/reference/androidx/xr/scenecore/SoundEffectPoolComponent) |

*** ** * ** ***

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

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

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

## Summary

| ### Public methods |
|---|---|
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/SoundEffectPoolComponent` | `https://developer.android.com/reference/androidx/xr/scenecore/SoundEffectPoolComponent#create(androidx.xr.runtime.Session,androidx.xr.scenecore.SoundEffectPool,androidx.xr.scenecore.PointSourceParams)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/runtime/Session session, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/SoundEffectPool soundEffectPool, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/PointSourceParams params )` Creates a `https://developer.android.com/reference/androidx/xr/scenecore/SoundEffectPoolComponent`. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/PointSourceParams` | `https://developer.android.com/reference/androidx/xr/scenecore/SoundEffectPoolComponent#getPointSourceParams()()` Updates the `https://developer.android.com/reference/androidx/xr/scenecore/PointSourceParams` used by the spatial audio source. |
| `void` | `https://developer.android.com/reference/androidx/xr/scenecore/SoundEffectPoolComponent#pause(androidx.xr.scenecore.Stream)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/Stream stream)` Pauses a currently playing sound stream. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/Stream` | `https://developer.android.com/reference/androidx/xr/scenecore/SoundEffectPoolComponent#play(androidx.xr.scenecore.SoundEffect,kotlin.Float,kotlin.Int,kotlin.Boolean)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/SoundEffect soundEffect, @https://developer.android.com/reference/androidx/annotation/FloatRange(from = 0.0, to = 1.0) float volume, @https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) int priority, boolean isLooping )` Plays a loaded sound effect. |
| `void` | `https://developer.android.com/reference/androidx/xr/scenecore/SoundEffectPoolComponent#resume(androidx.xr.scenecore.Stream)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/Stream stream)` Resumes a previously paused sound stream. |
| `void` | `https://developer.android.com/reference/androidx/xr/scenecore/SoundEffectPoolComponent#setLooping(androidx.xr.scenecore.Stream,kotlin.Boolean)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/Stream stream, boolean isLooping)` Updates the looping status of an active stream. |
| `final void` | `https://developer.android.com/reference/androidx/xr/scenecore/SoundEffectPoolComponent#setPointSourceParams(androidx.xr.scenecore.PointSourceParams)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/PointSourceParams value)` Updates the `https://developer.android.com/reference/androidx/xr/scenecore/PointSourceParams` used by the spatial audio source. |
| `void` | `https://developer.android.com/reference/androidx/xr/scenecore/SoundEffectPoolComponent#setVolume(androidx.xr.scenecore.Stream,kotlin.Float)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/Stream stream, @https://developer.android.com/reference/androidx/annotation/FloatRange(from = 0.0, to = 1.0) float volume )` Updates the volume of an active stream. |
| `void` | `https://developer.android.com/reference/androidx/xr/scenecore/SoundEffectPoolComponent#stop(androidx.xr.scenecore.Stream)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/Stream stream)` Stops a currently playing or paused sound stream and releases that stream ID. |

| ### Protected methods |
|---|---|
| `boolean` | `https://developer.android.com/reference/androidx/xr/scenecore/SoundEffectPoolComponent#onAttach(androidx.xr.scenecore.Entity)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/Entity entity)` Called by the framework when this component is being added to an `https://developer.android.com/reference/androidx/xr/scenecore/Entity`. |
| `void` | `https://developer.android.com/reference/androidx/xr/scenecore/SoundEffectPoolComponent#onDetach(androidx.xr.scenecore.Entity)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/Entity entity)` Called by the framework when this component is being removed from an `https://developer.android.com/reference/androidx/xr/scenecore/Entity`. |

## Public methods

### create

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

```
public static final @NonNull SoundEffectPoolComponent create(
    @NonNull Session session,
    @NonNull SoundEffectPool soundEffectPool,
    @NonNull PointSourceParams params
)
```

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

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

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

### getPointSourceParams

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

```
public final @NonNull PointSourceParams getPointSourceParams()
```

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

These pointSourceParams will apply to future playback requests.

### pause

```
public void pause(@NonNull Stream stream)
```

Pauses a currently playing sound stream.

If the `https://developer.android.com/reference/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 |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/Stream stream` | a `https://developer.android.com/reference/androidx/xr/scenecore/Stream` returned by `https://developer.android.com/reference/androidx/xr/scenecore/SoundEffectPlayer#play(androidx.xr.scenecore.SoundEffect,kotlin.Float,kotlin.Int,kotlin.Boolean)` |

### play

```
public @NonNull Stream play(
    @NonNull SoundEffect soundEffect,
    @FloatRange(from = 0.0, to = 1.0) float volume,
    @IntRange(from = 0) int priority,
    boolean isLooping
)
```

Plays a loaded sound effect.

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

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

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/Stream` | a `https://developer.android.com/reference/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

```
public void resume(@NonNull Stream stream)
```

Resumes a previously paused sound stream.

If the `https://developer.android.com/reference/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 |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/Stream stream` | a `https://developer.android.com/reference/androidx/xr/scenecore/Stream` returned by `https://developer.android.com/reference/androidx/xr/scenecore/SoundEffectPlayer#play(androidx.xr.scenecore.SoundEffect,kotlin.Float,kotlin.Int,kotlin.Boolean)` |

### setLooping

```
public void setLooping(@NonNull Stream stream, boolean isLooping)
```

Updates the looping status of an active stream.

If the `https://developer.android.com/reference/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 |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/Stream stream` | a `https://developer.android.com/reference/androidx/xr/scenecore/Stream` returned by `https://developer.android.com/reference/androidx/xr/scenecore/SoundEffectPlayer#play(androidx.xr.scenecore.SoundEffect,kotlin.Float,kotlin.Int,kotlin.Boolean)` |
| `boolean isLooping` | true to loop indefinitely, false to stop looping |

### setPointSourceParams

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

```
public final void setPointSourceParams(@NonNull PointSourceParams value)
```

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

These pointSourceParams will apply to future playback requests.

### setVolume

```
public void setVolume(
    @NonNull Stream stream,
    @FloatRange(from = 0.0, to = 1.0) float volume
)
```

Updates the volume of an active stream.

If the `https://developer.android.com/reference/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 |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/Stream stream` | a `https://developer.android.com/reference/androidx/xr/scenecore/Stream` returned by `https://developer.android.com/reference/androidx/xr/scenecore/SoundEffectPlayer#play(androidx.xr.scenecore.SoundEffect,kotlin.Float,kotlin.Int,kotlin.Boolean)` |
| `@https://developer.android.com/reference/androidx/annotation/FloatRange(from = 0.0, to = 1.0) float volume` | volume in the range 0.0 to 1.0 |

### stop

```
public void stop(@NonNull Stream stream)
```

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

If the `https://developer.android.com/reference/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 |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/Stream stream` | a `https://developer.android.com/reference/androidx/xr/scenecore/Stream` returned by `https://developer.android.com/reference/androidx/xr/scenecore/SoundEffectPlayer#play(androidx.xr.scenecore.SoundEffect,kotlin.Float,kotlin.Int,kotlin.Boolean)` |

## Protected methods

### onAttach

```
protected boolean onAttach(@NonNull Entity entity)
```

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

This method is triggered when `https://developer.android.com/reference/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/androidx/xr/scenecore/Component#onAttach(androidx.xr.scenecore.Entity)`.

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

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

### onDetach

```
protected void onDetach(@NonNull Entity entity)
```

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

This method is triggered when `https://developer.android.com/reference/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/androidx/xr/scenecore/Component#onAttach(androidx.xr.scenecore.Entity)`.

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