# SpatialSoundPool

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

*** ** * ** ***


```
public static class SpatialSoundPool
```

<br />

*** ** * ** ***

Provides spatial audio extensions on the framework `https://developer.android.com/reference/android/media/SoundPool.html` class.

## Summary

| ### Constants |
|---|---|
| `static final int` | `https://developer.android.com/reference/androidx/xr/scenecore/SpatialSoundPool#PLAY_FAILED() = 0` Indicates the failure of a `https://developer.android.com/reference/androidx/xr/scenecore/SpatialSoundPool#play(androidx.xr.runtime.Session,android.media.SoundPool,kotlin.Int,androidx.xr.scenecore.PointSourceParams,androidx.xr.scenecore.Entity,kotlin.Float,kotlin.Int,kotlin.Int,kotlin.Float)` method. |

| ### Public fields |
|---|---|
| `static @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/SpatialSoundPool` | `https://developer.android.com/reference/androidx/xr/scenecore/SpatialSoundPool#INSTANCE()` |

| ### Public methods |
|---|---|
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/SpatializerConstants.SourceType` | `https://developer.android.com/reference/androidx/xr/scenecore/SpatialSoundPool#getSpatialSourceType(androidx.xr.runtime.Session,android.media.SoundPool,kotlin.Int)( @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/android/media/SoundPool.html soundPool, int streamId )` |
| `static final int` | `https://developer.android.com/reference/androidx/xr/scenecore/SpatialSoundPool#play(androidx.xr.runtime.Session,android.media.SoundPool,kotlin.Int,androidx.xr.scenecore.SoundFieldAttributes,kotlin.Float,kotlin.Int,kotlin.Int,kotlin.Float)( @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/android/media/SoundPool.html soundPool, int soundID, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/SoundFieldAttributes attributes, @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, @https://developer.android.com/reference/androidx/annotation/IntRange(from = -1) int loop, @https://developer.android.com/reference/androidx/annotation/FloatRange(from = 0.5, to = 2.0) float rate )` Plays a spatialized sound effect as a sound field. |
| `static final int` | `https://developer.android.com/reference/androidx/xr/scenecore/SpatialSoundPool#play(androidx.xr.runtime.Session,android.media.SoundPool,kotlin.Int,androidx.xr.scenecore.PointSourceParams,androidx.xr.scenecore.Entity,kotlin.Float,kotlin.Int,kotlin.Int,kotlin.Float)( @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/android/media/SoundPool.html soundPool, int soundID, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/PointSourceParams params, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/Entity entity, @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, @https://developer.android.com/reference/androidx/annotation/IntRange(from = -1) int loop, @https://developer.android.com/reference/androidx/annotation/FloatRange(from = 0.5, to = 2.0) float rate )` Plays a spatialized sound effect emitted from the `https://developer.android.com/reference/androidx/xr/scenecore/Entity` in the `https://developer.android.com/reference/androidx/xr/scenecore/PointSourceParams`. |

## Constants

### PLAY_FAILED

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

```
public static final int PLAY_FAILED = 0
```

Indicates the failure of a `https://developer.android.com/reference/androidx/xr/scenecore/SpatialSoundPool#play(androidx.xr.runtime.Session,android.media.SoundPool,kotlin.Int,androidx.xr.scenecore.PointSourceParams,androidx.xr.scenecore.Entity,kotlin.Float,kotlin.Int,kotlin.Int,kotlin.Float)` method.

## Public fields

### INSTANCE

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

```
public static @NonNull SpatialSoundPool INSTANCE
```

## Public methods

### getSpatialSourceType

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

```
public final @NonNull SpatializerConstants.SourceType getSpatialSourceType(
    @NonNull Session session,
    @NonNull SoundPool soundPool,
    int streamId
)
```

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/runtime/Session session` | The current `https://developer.android.com/reference/androidx/xr/runtime/Session` instance. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/media/SoundPool.html soundPool` | The `https://developer.android.com/reference/android/media/SoundPool.html` to use to get its SourceType. |
| `int streamId` | a streamID returned by the `https://developer.android.com/reference/android/media/SoundPool.html#play(int, float, float, int, int, float)` or either `https://developer.android.com/reference/androidx/xr/scenecore/SpatialSoundPool#play(androidx.xr.runtime.Session,android.media.SoundPool,kotlin.Int,androidx.xr.scenecore.PointSourceParams,androidx.xr.scenecore.Entity,kotlin.Float,kotlin.Int,kotlin.Int,kotlin.Float)` method in this object. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/SpatializerConstants.SourceType` | The `https://developer.android.com/reference/androidx/xr/scenecore/SpatializerConstants.SourceType` for the given streamID. |

### play

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

```
public static final int play(
    @NonNull Session session,
    @NonNull SoundPool soundPool,
    int soundID,
    @NonNull SoundFieldAttributes attributes,
    @FloatRange(from = 0.0, to = 1.0) float volume,
    @IntRange(from = 0) int priority,
    @IntRange(from = -1) int loop,
    @FloatRange(from = 0.5, to = 2.0) float rate
)
```

Plays a spatialized sound effect as a sound field.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/runtime/Session session` | The current `https://developer.android.com/reference/androidx/xr/runtime/Session` instance. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/media/SoundPool.html soundPool` | The `https://developer.android.com/reference/android/media/SoundPool.html` to use to the play the sound. |
| `int soundID` | a soundId returned by the `https://developer.android.com/reference/android/media/SoundPool.html#load(android.content.Context, int, int)` function. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/SoundFieldAttributes attributes` | `https://developer.android.com/reference/androidx/xr/scenecore/SoundFieldAttributes` to configure the sound source. |
| `@https://developer.android.com/reference/androidx/annotation/FloatRange(from = 0.0, to = 1.0) float volume` | value (range = 0.0 to 1.0) |
| `@https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) int priority` | stream priority (0 = lowest priority) |
| `@https://developer.android.com/reference/androidx/annotation/IntRange(from = -1) int loop` | loop mode (0 = no loop, -1 = loop forever, N = loop N times) |
| `@https://developer.android.com/reference/androidx/annotation/FloatRange(from = 0.5, to = 2.0) float rate` | playback rate (1.0 = normal playback, range 0.5 to 2.0) |

| Returns |
|---|---|
| `int` | non-zero streamID if successful, `https://developer.android.com/reference/androidx/xr/scenecore/SpatialSoundPool#PLAY_FAILED()` if failed |

### play

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

```
public static final int play(
    @NonNull Session session,
    @NonNull SoundPool soundPool,
    int soundID,
    @NonNull PointSourceParams params,
    @NonNull Entity entity,
    @FloatRange(from = 0.0, to = 1.0) float volume,
    @IntRange(from = 0) int priority,
    @IntRange(from = -1) int loop,
    @FloatRange(from = 0.5, to = 2.0) float rate
)
```

Plays a spatialized sound effect emitted from the `https://developer.android.com/reference/androidx/xr/scenecore/Entity` in the `https://developer.android.com/reference/androidx/xr/scenecore/PointSourceParams`.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/runtime/Session session` | The current `https://developer.android.com/reference/androidx/xr/runtime/Session` instance. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/media/SoundPool.html soundPool` | The `https://developer.android.com/reference/android/media/SoundPool.html` to use to the play the sound. |
| `int soundID` | a soundId returned by the `https://developer.android.com/reference/android/media/SoundPool.html#load(android.content.Context, int, int)` function. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/PointSourceParams params` | `https://developer.android.com/reference/androidx/xr/scenecore/PointSourceParams` to configure the sound source. |
| `@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 the sound will be played. |
| `@https://developer.android.com/reference/androidx/annotation/FloatRange(from = 0.0, to = 1.0) float volume` | value (range = 0.0 to 1.0) |
| `@https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) int priority` | stream priority (0 = lowest priority) |
| `@https://developer.android.com/reference/androidx/annotation/IntRange(from = -1) int loop` | loop mode (0 = no loop, -1 = loop forever, N = loop N times) |
| `@https://developer.android.com/reference/androidx/annotation/FloatRange(from = 0.5, to = 2.0) float rate` | playback rate (1.0 = normal playback, range 0.5 to 2.0) |

| Returns |
|---|---|
| `int` | non-zero streamID if successful, `https://developer.android.com/reference/androidx/xr/scenecore/SpatialSoundPool#PLAY_FAILED()` if failed. |