# SoundFieldAudioComponent

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

*** ** * ** ***


```
class SoundFieldAudioComponent : Component
```

<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.SoundFieldAudioComponent](https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SoundFieldAudioComponent) |

*** ** * ** ***

Provides spatial audio playback for a sound field associated with an `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity`.

It provides an `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/audio/AudioOutputProvider` which can be used to configure an ExoPlayer.Builder instance for sound field audio playback. The characteristics of the sound field are defined by `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SoundFieldAttributes`.

This component can only be attached to one `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity` at a time.

## Summary

| ### Public companion functions |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SoundFieldAudioComponent` | `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SoundFieldAudioComponent#create(androidx.xr.runtime.Session,androidx.xr.scenecore.SoundFieldAttributes)(session: https://developer.android.com/reference/kotlin/androidx/xr/runtime/Session, attributes: https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SoundFieldAttributes)` Creates a `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SoundFieldAudioComponent` for the given `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SoundFieldAudioComponent.Companion#create(androidx.xr.runtime.Session,androidx.xr.scenecore.SoundFieldAttributes)` and initializes it with the provided `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SoundFieldAudioComponent.Companion#create(androidx.xr.runtime.Session,androidx.xr.scenecore.SoundFieldAttributes)`. |

| ### Protected functions |
|---|---|
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SoundFieldAudioComponent#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/SoundFieldAudioComponent#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/media3/exoplayer/audio/AudioOutputProvider` | `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SoundFieldAudioComponent#audioOutputProvider()` An `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/audio/AudioOutputProvider` that can be used to configure an `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/ExoPlayer.Builder` for [ambisonics](https://developer.android.com/develop/xr/jetpack-xr-sdk/add-spatial-audio#ambionics_example) audio playback. |

## 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, attributes: SoundFieldAttributes): SoundFieldAudioComponent
```

Creates a `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SoundFieldAudioComponent` for the given `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SoundFieldAudioComponent.Companion#create(androidx.xr.runtime.Session,androidx.xr.scenecore.SoundFieldAttributes)` and initializes it with the provided `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SoundFieldAudioComponent.Companion#create(androidx.xr.runtime.Session,androidx.xr.scenecore.SoundFieldAttributes)`.

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

### audioOutputProvider

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

```
val audioOutputProvider: AudioOutputProvider
```

An `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/audio/AudioOutputProvider` that can be used to configure an `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/ExoPlayer.Builder` for [ambisonics](https://developer.android.com/develop/xr/jetpack-xr-sdk/add-spatial-audio#ambionics_example) audio playback. An `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/audio/AudioOutputProvider` can only be bound with one Exoplayer instance and should not be re-used with other instances.