---
title: "spatializedAudioOutput"
description: "Adds spatialized audio output to this Composable."
type: "function"
lastmod: "2026-07-19T07:47:45.716424Z"
---
## API Reference

### spatializedAudioOutput

> Source set: Android

```kotlin
public fun SubspaceModifier.spatializedAudioOutput(
    spatializedAudioOutput: SpatializedAudioOutput
): SubspaceModifier
```

Adds spatialized audio output to this Composable. Use [PointSourceExoplayerAudioOutput](/jetpack-compose/androidx.xr.compose/compose/classes/PointSourceExoplayerAudioOutput),
[SoundFieldExoplayerAudioOutput](/jetpack-compose/androidx.xr.compose/compose/classes/SoundFieldExoplayerAudioOutput) or [SoundEffectPoolComponent.asSpatializedAudioOutput](/jetpack-compose/androidx.xr.compose/compose/functions/asSpatializedAudioOutput) to create
an object capable of spatializing audio.

#### Parameters

| | |
| --- | --- |
| spatializedAudioOutput | A [SpatializedAudioOutput](/jetpack-compose/androidx.xr.compose/compose/classes/SpatializedAudioOutput) to be added to this Composable. A [SpatializedAudioOutput](/jetpack-compose/androidx.xr.compose/compose/classes/SpatializedAudioOutput) should only be attached to one Composable at a time. If it is attached multiple times, its associated audio output will become head locked. |

## Code Examples
### SoundEffectPlayerSample
```kotlin
/** A sample demonstrating a spatialized sound effect player. */
@Composable
fun SoundEffectPlayerSample() {
    val context = LocalContext.current
    val session = LocalSession.current ?: return
    // Create a SoundEffectPool.
    val soundEffectPool = remember { SoundEffectPool.create(session, maxStreams = 10) }
    // Remember a sound effect loaded via AssetFileDescriptor.
    val soundEffect = remember {
        val assetFileDescriptor = context.assets.openFd("click.wav")
        soundEffectPool.load(assetFileDescriptor)
    }
    // Create a SoundEffectPoolComponent.
    val soundEffectPoolComponent =
        remember(session, soundEffectPool) {
            SoundEffectPoolComponent.create(session, soundEffectPool, PointSourceParams())
        }
    // Attach the SpatializedAudioOutput via SubspaceModifier.spatializedAudioOutput.
    SpatialPanel(
        modifier =
            SubspaceModifier.width(600.dp)
                .height(400.dp)
                .spatializedAudioOutput(soundEffectPoolComponent.asSpatializedAudioOutput())
                .movable()
    ) {
        Button(
            onClick = {
                soundEffectPoolComponent.play(
                    soundEffect,
                    volume = 1f,
                    priority = 0,
                    isLooping = false,
                )
            }
        ) {
            Text("Play Sound Effect")
        }
    }
}
```
### SoundFieldSpatializedAudioOutputSample
```kotlin
/** A sample demonstrating a sound field spatialized audio output with ExoPlayer. */
@Composable
fun SoundFieldSpatializedAudioOutputSample() {
    val context = LocalContext.current
    val session = LocalSession.current ?: return
    // Create a SoundFieldExoplayerAudioOutput.
    val audioOutput = remember {
        SoundFieldExoplayerAudioOutput(
            session,
            SoundFieldAttributes(SpatializerConstants.AmbisonicsOrder.FIRST_ORDER),
        )
    }
    // Create an ExoPlayer and set its AudioOutputProvider.
    val exoPlayer = remember {
        ExoPlayer.Builder(context).setAudioOutputProvider(audioOutput.audioOutputProvider).build()
    }
    DisposableEffect(Unit) {
        exoPlayer.setMediaItem(MediaItem.fromUri("asset:///ambient.mp3"))
        exoPlayer.prepare()
        exoPlayer.play()
        onDispose { exoPlayer.release() }
    }
    // Attach the SpatializedAudioOutput via SubspaceModifier.spatializedAudioOutput.
    SpatialPanel(
        modifier =
            SubspaceModifier.width(600.dp)
                .height(400.dp)
                .spatializedAudioOutput(audioOutput)
                .movable()
    ) {
        // Content of the panel
    }
}
```
### SpatializedAudioOutputSample
```kotlin
/** A sample demonstrating a point source spatialized audio output with ExoPlayer. */
@Composable
fun SpatializedAudioOutputSample() {
    val context = LocalContext.current
    // Create a PointSourceExoplayerAudioOutput.
    val audioOutput = rememberPointSourceExoplayerAudioOutput(PointSourceParams())
    // Create an ExoPlayer and set its AudioOutputProvider.
    val exoPlayer = remember {
        ExoPlayer.Builder(context).setAudioOutputProvider(audioOutput.audioOutputProvider).build()
    }
    DisposableEffect(Unit) {
        exoPlayer.setMediaItem(MediaItem.fromUri("asset:///audio.mp3"))
        exoPlayer.prepare()
        exoPlayer.play()
        onDispose { exoPlayer.release() }
    }
    // Attach the SpatializedAudioOutput via SubspaceModifier.spatializedAudioOutput. The audio will
    // be spatialized from the position of this SpatialPanel, and will follow the Panel as it moves.
    SpatialPanel(
        modifier =
            SubspaceModifier.width(600.dp)
                .height(400.dp)
                .spatializedAudioOutput(audioOutput)
                .movable()
    ) {
        // Content of the panel
    }
}
```
