# SpatialAudioTrack

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

*** ** * ** ***


```
public static class SpatialAudioTrack
```

<br />

*** ** * ** ***

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

## Summary

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

| ### Public methods |
|---|---|
| `static final https://developer.android.com/reference/androidx/xr/scenecore/PointSourceParams` | `https://developer.android.com/reference/androidx/xr/scenecore/SpatialAudioTrack#getPointSourceParams(androidx.xr.runtime.Session,android.media.AudioTrack)(@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/AudioTrack.html track)` Gets the `https://developer.android.com/reference/androidx/xr/scenecore/PointSourceParams` of the provided `https://developer.android.com/reference/android/media/AudioTrack.html`. |
| `static final https://developer.android.com/reference/androidx/xr/scenecore/SoundFieldAttributes` | `https://developer.android.com/reference/androidx/xr/scenecore/SpatialAudioTrack#getSoundFieldAttributes(androidx.xr.runtime.Session,android.media.AudioTrack)( @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/AudioTrack.html track )` Gets the `https://developer.android.com/reference/androidx/xr/scenecore/SoundFieldAttributes` of the provided `https://developer.android.com/reference/android/media/AudioTrack.html`. |
| `static 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/SpatialAudioTrack#getSpatialSourceType(androidx.xr.runtime.Session,android.media.AudioTrack)(@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/AudioTrack.html track)` Gets the `https://developer.android.com/reference/androidx/xr/scenecore/SpatializerConstants.SourceType` of the provided `https://developer.android.com/reference/android/media/AudioTrack.html`. |
| `static final void` | `https://developer.android.com/reference/androidx/xr/scenecore/SpatialAudioTrack#setPointSourceParams(androidx.xr.runtime.Session,android.media.AudioTrack,androidx.xr.scenecore.PointSourceParams,androidx.xr.scenecore.Entity)( @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/AudioTrack.html track, @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 )` Sets a new `https://developer.android.com/reference/androidx/xr/scenecore/PointSourceParams` on the provided `https://developer.android.com/reference/android/media/AudioTrack.html`. |

## Public fields

### INSTANCE

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

```
public static @NonNull SpatialAudioTrack INSTANCE
```

## Public methods

### getPointSourceParams

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

```
public static final PointSourceParams getPointSourceParams(@NonNull Session session, @NonNull AudioTrack track)
```

Gets the `https://developer.android.com/reference/androidx/xr/scenecore/PointSourceParams` of the provided `https://developer.android.com/reference/android/media/AudioTrack.html`.

| 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/AudioTrack.html track` | The `https://developer.android.com/reference/android/media/AudioTrack.html` from which to get the `https://developer.android.com/reference/androidx/xr/scenecore/PointSourceParams`. |

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/xr/scenecore/PointSourceParams` | The `https://developer.android.com/reference/androidx/xr/scenecore/PointSourceParams` of the provided track, null if not set. |

### getSoundFieldAttributes

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

```
public static final SoundFieldAttributes getSoundFieldAttributes(
    @NonNull Session session,
    @NonNull AudioTrack track
)
```

Gets the `https://developer.android.com/reference/androidx/xr/scenecore/SoundFieldAttributes` of the provided `https://developer.android.com/reference/android/media/AudioTrack.html`.

| 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/AudioTrack.html track` | The `https://developer.android.com/reference/android/media/AudioTrack.html` from which to get the `https://developer.android.com/reference/androidx/xr/scenecore/SoundFieldAttributes`. |

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/xr/scenecore/SoundFieldAttributes` | The `https://developer.android.com/reference/androidx/xr/scenecore/SoundFieldAttributes` of the provided track, null if not set. |

### getSpatialSourceType

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

```
public static final @NonNull SpatializerConstants.SourceType getSpatialSourceType(@NonNull Session session, @NonNull AudioTrack track)
```

Gets the `https://developer.android.com/reference/androidx/xr/scenecore/SpatializerConstants.SourceType` of the provided `https://developer.android.com/reference/android/media/AudioTrack.html`. If `https://developer.android.com/reference/androidx/xr/scenecore/SpatialAudioTrack#setPointSourceParams(androidx.xr.runtime.Session,android.media.AudioTrack,androidx.xr.scenecore.PointSourceParams,androidx.xr.scenecore.Entity)` has not yet been called, this value is determined by how the `https://developer.android.com/reference/androidx/xr/scenecore/SpatialAudioTrackBuilder` was constructed. Will return `https://developer.android.com/reference/androidx/xr/scenecore/SpatializerConstants.SourceType#DEFAULT()` for tracks that didn't use spatial audio attributes.

| 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/AudioTrack.html track` | The `https://developer.android.com/reference/android/media/AudioTrack.html` from which to get the `https://developer.android.com/reference/androidx/xr/scenecore/SpatializerConstants.SourceType`. |

| 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` of the provided track. |

### setPointSourceParams

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

```
public static final void setPointSourceParams(
    @NonNull Session session,
    @NonNull AudioTrack track,
    @NonNull PointSourceParams params,
    @NonNull Entity entity
)
```

Sets a new `https://developer.android.com/reference/androidx/xr/scenecore/PointSourceParams` on the provided `https://developer.android.com/reference/android/media/AudioTrack.html`.

The new `https://developer.android.com/reference/androidx/xr/scenecore/PointSourceParams` will be applied if the `https://developer.android.com/reference/androidx/xr/scenecore/SpatializerConstants.SourceType` of the AudioTrack was either `https://developer.android.com/reference/androidx/xr/scenecore/SpatializerConstants.SourceType#DEFAULT()` or `https://developer.android.com/reference/androidx/xr/scenecore/SpatializerConstants.SourceType#POINT_SOURCE()`. If the `https://developer.android.com/reference/androidx/xr/scenecore/SpatializerConstants.SourceType` was `https://developer.android.com/reference/androidx/xr/scenecore/SpatializerConstants.SourceType#SOUND_FIELD()`, then this method will throw an `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-state-exception/index.html`.

| 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/AudioTrack.html track` | The `https://developer.android.com/reference/android/media/AudioTrack.html` on which to set the `https://developer.android.com/reference/androidx/xr/scenecore/PointSourceParams`. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/PointSourceParams params` | The `https://developer.android.com/reference/androidx/xr/scenecore/PointSourceParams` to be set. |
| `@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. |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-state-exception/index.html` | if the `https://developer.android.com/reference/androidx/xr/scenecore/SpatializerConstants.SourceType` of the `https://developer.android.com/reference/android/media/AudioTrack.html` is `https://developer.android.com/reference/androidx/xr/scenecore/SpatializerConstants.SourceType#SOUND_FIELD()`. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html` | if the `https://developer.android.com/reference/androidx/xr/scenecore/PointSourceParams` cannot be set on this `https://developer.android.com/reference/android/media/AudioTrack.html` instance. |