# PositionalAudioComponent

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

*** ** * ** ***


```
public final class PositionalAudioComponent extends Component
```

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

*** ** * ** ***

A Component that provides positional spatial audio playback for an `https://developer.android.com/reference/androidx/xr/scenecore/Entity`.

It provides an `https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioOutputProvider` which can be used to configure an `https://developer.android.com/reference/androidx/media3/exoplayer/ExoPlayer.Builder` instance for positional audio playback.

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.

## Summary

| ### Public methods |
|---|---|
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/PositionalAudioComponent` | `https://developer.android.com/reference/androidx/xr/scenecore/PositionalAudioComponent#create(androidx.xr.runtime.Session,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/PointSourceParams params)` Creates a `https://developer.android.com/reference/androidx/xr/scenecore/PositionalAudioComponent` for the given `https://developer.android.com/reference/androidx/xr/scenecore/PositionalAudioComponent.Companion#create(androidx.xr.runtime.Session,androidx.xr.scenecore.PointSourceParams)` and initializes it with the provided `https://developer.android.com/reference/androidx/xr/scenecore/PositionalAudioComponent.Companion#create(androidx.xr.runtime.Session,androidx.xr.scenecore.PointSourceParams)`. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioOutputProvider` | `https://developer.android.com/reference/androidx/xr/scenecore/PositionalAudioComponent#getAudioOutputProvider()()` An `https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioOutputProvider` that can be used to configure an `https://developer.android.com/reference/androidx/media3/exoplayer/ExoPlayer.Builder` for positional audio playback. |
| `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/PositionalAudioComponent#getPointSourceParams()()` Updates the `https://developer.android.com/reference/androidx/xr/scenecore/PointSourceParams` used by the spatial audio source. |
| `final void` | `https://developer.android.com/reference/androidx/xr/scenecore/PositionalAudioComponent#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. |

| ### Protected methods |
|---|---|
| `boolean` | `https://developer.android.com/reference/androidx/xr/scenecore/PositionalAudioComponent#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/PositionalAudioComponent#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 PositionalAudioComponent create(@NonNull Session session, @NonNull PointSourceParams params)
```

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

### getAudioOutputProvider

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

```
public final @NonNull AudioOutputProvider getAudioOutputProvider()
```

An `https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioOutputProvider` that can be used to configure an `https://developer.android.com/reference/androidx/media3/exoplayer/ExoPlayer.Builder` for positional audio playback. An `https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioOutputProvider` can only be bound with one Exoplayer instance and should not be re-used with other instances.

### 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 currently playing audio and future playback requests.

### 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 currently playing audio and future playback requests.

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