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

*** ** * ** ***


```
object SpatialSoundPool
```

<br />

*** ** * ** ***

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

## Summary

| ### Constants |
|---|---|
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SpatialSoundPool#PLAY_FAILED() = 0` Indicates the failure of a `https://developer.android.com/reference/kotlin/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 functions |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SpatializerConstants.SourceType` | `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SpatialSoundPool#getSpatialSourceType(androidx.xr.runtime.Session,android.media.SoundPool,kotlin.Int)(session: https://developer.android.com/reference/kotlin/androidx/xr/runtime/Session, soundPool: https://developer.android.com/reference/android/media/SoundPool.html, streamId: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/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)( session: https://developer.android.com/reference/kotlin/androidx/xr/runtime/Session, soundPool: https://developer.android.com/reference/android/media/SoundPool.html, soundID: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, attributes: https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SoundFieldAttributes, 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, loop: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = -1) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, rate: @https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = 0.5, to = 2.0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html )` Plays a spatialized sound effect as a sound field. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/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)( session: https://developer.android.com/reference/kotlin/androidx/xr/runtime/Session, soundPool: https://developer.android.com/reference/android/media/SoundPool.html, soundID: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, params: https://developer.android.com/reference/kotlin/androidx/xr/scenecore/PointSourceParams, entity: https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity, 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, loop: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = -1) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, rate: @https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = 0.5, to = 2.0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html )` Plays a spatialized sound effect emitted from the `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity` in the `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/PointSourceParams`. |

## Constants

### PLAY_FAILED

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

```
const val PLAY_FAILED = 0: Int
```

Indicates the failure of a `https://developer.android.com/reference/kotlin/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 functions

### getSpatialSourceType

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

```
fun getSpatialSourceType(session: Session, soundPool: SoundPool, streamId: Int): SpatializerConstants.SourceType
```

| Parameters |
|---|---|
| `session: https://developer.android.com/reference/kotlin/androidx/xr/runtime/Session` | The current `https://developer.android.com/reference/kotlin/androidx/xr/runtime/Session` instance. |
| `soundPool: https://developer.android.com/reference/android/media/SoundPool.html` | The `https://developer.android.com/reference/android/media/SoundPool.html` to use to get its SourceType. |
| `streamId: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | 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/kotlin/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/kotlin/androidx/xr/scenecore/SpatializerConstants.SourceType` | The `https://developer.android.com/reference/kotlin/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)

```
fun play(
    session: Session,
    soundPool: SoundPool,
    soundID: Int,
    attributes: SoundFieldAttributes,
    volume: @FloatRange(from = 0.0, to = 1.0) Float = 1.0f,
    priority: @IntRange(from = 0) Int = 0,
    loop: @IntRange(from = -1) Int = 0,
    rate: @FloatRange(from = 0.5, to = 2.0) Float = 1.0f
): Int
```

Plays a spatialized sound effect as a sound field.

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

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | non-zero streamID if successful, `https://developer.android.com/reference/kotlin/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)

```
fun play(
    session: Session,
    soundPool: SoundPool,
    soundID: Int,
    params: PointSourceParams,
    entity: Entity,
    volume: @FloatRange(from = 0.0, to = 1.0) Float = 1.0f,
    priority: @IntRange(from = 0) Int = 0,
    loop: @IntRange(from = -1) Int = 0,
    rate: @FloatRange(from = 0.5, to = 2.0) Float = 1.0f
): Int
```

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

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

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | non-zero streamID if successful, `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SpatialSoundPool#PLAY_FAILED()` if failed. |