Added in [API level 32](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Nested Classes](https://developer.android.com/reference/android/media/Spatializer#nestedclasses) \| [Constants](https://developer.android.com/reference/android/media/Spatializer#constants) \| [Methods](https://developer.android.com/reference/android/media/Spatializer#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/android/media/Spatializer#inhmethods)

# Spatializer

*** ** * ** ***

[Kotlin](https://developer.android.com/reference/kotlin/android/media/Spatializer "View this page in Kotlin") \|Java


`
public


class
Spatializer
`


`

extends https://developer.android.com/reference/java/lang/Object


`

`


`

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.media.Spatializer |

<br />

*** ** * ** ***

Spatializer provides access to querying capabilities and behavior of sound spatialization
on the device.
Sound spatialization simulates sounds originating around the listener as if they were coming
from virtual speakers placed around the listener.  

Support for spatialization is optional, use `https://developer.android.com/reference/android/media/AudioManager#getSpatializer()` to obtain an
instance of this class if the feature is supported.

## Summary

| ### Nested classes ||
|---|---|
| ` interface` | `https://developer.android.com/reference/android/media/Spatializer.OnHeadTrackerAvailableListener` Interface to be notified of changes to the availability of a head tracker on the audio device to be used by the spatializer effect. |
| ` interface` | `https://developer.android.com/reference/android/media/Spatializer.OnSpatializerStateChangedListener` An interface to be notified of changes to the state of the spatializer effect. |

| ### Constants ||
|---|---|
| `int` | `https://developer.android.com/reference/android/media/Spatializer#SPATIALIZER_IMMERSIVE_LEVEL_MULTICHANNEL` Constant indicating the `Spatializer` on this device supports multichannel spatialization. |
| `int` | `https://developer.android.com/reference/android/media/Spatializer#SPATIALIZER_IMMERSIVE_LEVEL_NONE` Constant indicating there are no spatialization capabilities supported on this device. |
| `int` | `https://developer.android.com/reference/android/media/Spatializer#SPATIALIZER_IMMERSIVE_LEVEL_OTHER` Constant indicating the `Spatializer` on this device supports a spatialization mode that differs from the ones available at this SDK level. |

| ### Public methods ||
|---|---|
| ` void` | ` https://developer.android.com/reference/android/media/Spatializer#addOnHeadTrackerAvailableListener(java.util.concurrent.Executor,%20android.media.Spatializer.OnHeadTrackerAvailableListener)(https://developer.android.com/reference/java/util/concurrent/Executor executor, https://developer.android.com/reference/android/media/Spatializer.OnHeadTrackerAvailableListener listener) ` Adds a listener to be notified of changes to the availability of a head tracker. |
| ` void` | ` https://developer.android.com/reference/android/media/Spatializer#addOnSpatializerStateChangedListener(java.util.concurrent.Executor,%20android.media.Spatializer.OnSpatializerStateChangedListener)(https://developer.android.com/reference/java/util/concurrent/Executor executor, https://developer.android.com/reference/android/media/Spatializer.OnSpatializerStateChangedListener listener) ` Adds a listener to be notified of changes to the enabled state of the `Spatializer`. |
| ` boolean` | ` https://developer.android.com/reference/android/media/Spatializer#canBeSpatialized(android.media.AudioAttributes,%20android.media.AudioFormat)(https://developer.android.com/reference/android/media/AudioAttributes attributes, https://developer.android.com/reference/android/media/AudioFormat format) ` Returns whether audio of the given `https://developer.android.com/reference/android/media/AudioFormat`, played with the given `https://developer.android.com/reference/android/media/AudioAttributes` can be spatialized. |
| ` int` | ` https://developer.android.com/reference/android/media/Spatializer#getImmersiveAudioLevel()() ` Return the level of support for the spatialization feature on this device. |
| ` https://developer.android.com/reference/java/util/List<https://developer.android.com/reference/java/lang/Integer>` | ` https://developer.android.com/reference/android/media/Spatializer#getSpatializedChannelMasks()() ` Returns a list of channel masks that represent the widest channel masks the spatializer is capable of rendering with individual channel positions. |
| ` boolean` | ` https://developer.android.com/reference/android/media/Spatializer#isAvailable()() ` Returns whether spatialization is available. |
| ` boolean` | ` https://developer.android.com/reference/android/media/Spatializer#isEnabled()() ` Returns whether spatialization is enabled or not. |
| ` boolean` | ` https://developer.android.com/reference/android/media/Spatializer#isHeadTrackerAvailable()() ` Returns whether a head tracker is currently available for the audio device used by the spatializer effect. |
| ` void` | ` https://developer.android.com/reference/android/media/Spatializer#removeOnHeadTrackerAvailableListener(android.media.Spatializer.OnHeadTrackerAvailableListener)(https://developer.android.com/reference/android/media/Spatializer.OnHeadTrackerAvailableListener listener) ` Removes a previously registered listener for the availability of a head tracker. |
| ` void` | ` https://developer.android.com/reference/android/media/Spatializer#removeOnSpatializerStateChangedListener(android.media.Spatializer.OnSpatializerStateChangedListener)(https://developer.android.com/reference/android/media/Spatializer.OnSpatializerStateChangedListener listener) ` Removes a previously added listener for changes to the enabled state of the `Spatializer`. |

| ### Inherited methods |
|---|---|
| From class ` https://developer.android.com/reference/java/lang/Object ` |---|---| | ` https://developer.android.com/reference/java/lang/Object` | ` https://developer.android.com/reference/java/lang/Object#clone()() ` Creates and returns a copy of this object. | | ` boolean` | ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) ` Indicates whether some other object is "equal to" this one. | | ` void` | ` https://developer.android.com/reference/java/lang/Object#finalize()() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. | | ` final https://developer.android.com/reference/java/lang/Class<?>` | ` https://developer.android.com/reference/java/lang/Object#getClass()() ` Returns the runtime class of this `Object`. | | ` int` | ` https://developer.android.com/reference/java/lang/Object#hashCode()() ` Returns a hash code value for the object. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#notify()() ` Wakes up a single thread that is waiting on this object's monitor. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#notifyAll()() ` Wakes up all threads that are waiting on this object's monitor. | | ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/java/lang/Object#toString()() ` Returns a string representation of the object. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos) ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis) ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait()() ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*. | ||

## Constants

### SPATIALIZER_IMMERSIVE_LEVEL_MULTICHANNEL

Added in [API level 32](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int SPATIALIZER_IMMERSIVE_LEVEL_MULTICHANNEL
```

Constant indicating the `Spatializer` on this device supports multichannel
spatialization.

<br />

**See also:**

- `https://developer.android.com/reference/android/media/Spatializer#getImmersiveAudioLevel()`

Constant Value:

1
(0x00000001)


### SPATIALIZER_IMMERSIVE_LEVEL_NONE

Added in [API level 32](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int SPATIALIZER_IMMERSIVE_LEVEL_NONE
```

Constant indicating there are no spatialization capabilities supported on this device.

<br />

**See also:**

- `https://developer.android.com/reference/android/media/Spatializer#getImmersiveAudioLevel()`

Constant Value:

0
(0x00000000)


### SPATIALIZER_IMMERSIVE_LEVEL_OTHER

Added in [API level 32](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int SPATIALIZER_IMMERSIVE_LEVEL_OTHER
```

Constant indicating the `Spatializer` on this device supports a spatialization
mode that differs from the ones available at this SDK level.

<br />

**See also:**

- `https://developer.android.com/reference/android/media/Spatializer#getImmersiveAudioLevel()`

Constant Value:

-1
(0xffffffff)


## Public methods

### addOnHeadTrackerAvailableListener

Added in [API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void addOnHeadTrackerAvailableListener (Executor executor, 
                Spatializer.OnHeadTrackerAvailableListener listener)
```

Adds a listener to be notified of changes to the availability of a head tracker.

<br />

| Parameters ||
|---|---|
| `executor` | `Executor`: the `Executor` handling the callback. This value cannot be `null`. Callback and listener events are dispatched through this `https://developer.android.com/reference/java/util/concurrent/Executor`, providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use `https://developer.android.com/reference/android/content/Context#getMainExecutor()`. Otherwise, provide an `https://developer.android.com/reference/java/util/concurrent/Executor` that dispatches to an appropriate thread. <br /> |
| `listener` | `Spatializer.OnHeadTrackerAvailableListener`: the listener to receive availability updates. This value cannot be `null`. <br /> |

**See also:**

- `https://developer.android.com/reference/android/media/Spatializer#removeOnHeadTrackerAvailableListener(android.media.Spatializer.OnHeadTrackerAvailableListener)`

### addOnSpatializerStateChangedListener

Added in [API level 32](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void addOnSpatializerStateChangedListener (Executor executor, 
                Spatializer.OnSpatializerStateChangedListener listener)
```

Adds a listener to be notified of changes to the enabled state of the
`Spatializer`.

<br />

| Parameters ||
|---|---|
| `executor` | `Executor`: the `Executor` handling the callback. This value cannot be `null`. Callback and listener events are dispatched through this `https://developer.android.com/reference/java/util/concurrent/Executor`, providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use `https://developer.android.com/reference/android/content/Context#getMainExecutor()`. Otherwise, provide an `https://developer.android.com/reference/java/util/concurrent/Executor` that dispatches to an appropriate thread. <br /> |
| `listener` | `Spatializer.OnSpatializerStateChangedListener`: the listener to receive enabled state updates. This value cannot be `null`. <br /> |

**See also:**

- `https://developer.android.com/reference/android/media/Spatializer#isEnabled()`

### canBeSpatialized

Added in [API level 32](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean canBeSpatialized (AudioAttributes attributes, 
                AudioFormat format)
```

Returns whether audio of the given `https://developer.android.com/reference/android/media/AudioFormat`, played with the given
`https://developer.android.com/reference/android/media/AudioAttributes` can be spatialized.
Note that the result reflects the capabilities of the device and may change when
audio accessories are connected/disconnected (e.g. wired headphones plugged in or not).
The result is independent from whether spatialization processing is enabled or not.

<br />

| Parameters ||
|---|---|
| `attributes` | `AudioAttributes`: the `AudioAttributes` of the content as used for playback. This value cannot be `null`. <br /> |
| `format` | `AudioFormat`: the `AudioFormat` of the content as used for playback. This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `boolean` | `true` if the device is capable of spatializing the combination of audio format and attributes, `false` otherwise. <br /> |

### getImmersiveAudioLevel

Added in [API level 32](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int getImmersiveAudioLevel ()
```

Return the level of support for the spatialization feature on this device.
This level of support is independent of whether the `Spatializer` is currently
enabled or available and will not change over time.

<br />

| Returns ||
|---|---|
| `int` | the level of spatialization support. Value is one of the following: - `https://developer.android.com/reference/android/media/Spatializer#SPATIALIZER_IMMERSIVE_LEVEL_OTHER` - `https://developer.android.com/reference/android/media/Spatializer#SPATIALIZER_IMMERSIVE_LEVEL_NONE` - `https://developer.android.com/reference/android/media/Spatializer#SPATIALIZER_IMMERSIVE_LEVEL_MULTICHANNEL` |

**See also:**

- `https://developer.android.com/reference/android/media/Spatializer#isEnabled()`
- `https://developer.android.com/reference/android/media/Spatializer#isAvailable()`

### getSpatializedChannelMasks

Added in [API level 36](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public List<Integer> getSpatializedChannelMasks ()
```

Returns a list of channel masks that represent the widest channel masks the spatializer
is capable of rendering with individual channel positions.
For instance a spatializer may only support virtual speaker positions for 5.1, it would
therefore return `https://developer.android.com/reference/android/media/AudioFormat#CHANNEL_OUT_5POINT1`. But it would still return
`true` when querying `https://developer.android.com/reference/android/media/Spatializer#canBeSpatialized(android.media.AudioAttributes,%20android.media.AudioFormat)` it
with a channel mask of `https://developer.android.com/reference/android/media/AudioFormat#CHANNEL_OUT_7POINT1POINT2`: the sound present
in each channel would still be heard, but the sounds from the rear, side and top pairs would
be mixed together, and be spatialized at the same location.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/List<https://developer.android.com/reference/java/lang/Integer>` | a list of channel masks following the `CHANNEL_OUT_*` output channel definitions found in `https://developer.android.com/reference/android/media/AudioFormat`. This value cannot be `null`. <br /> |

### isAvailable

Added in [API level 32](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean isAvailable ()
```

Returns whether spatialization is available.
Reasons for spatialization being unavailable include situations where audio output is
incompatible with sound spatialization, such as playback on a monophonic speaker.  

Note that spatialization can be available, but disabled by the user, in which case this
method would still return `true`, whereas `https://developer.android.com/reference/android/media/Spatializer#isEnabled()`
would return `false`.  

Also when the feature is not supported on the device (indicated
by `https://developer.android.com/reference/android/media/Spatializer#getImmersiveAudioLevel()` returning `https://developer.android.com/reference/android/media/Spatializer#SPATIALIZER_IMMERSIVE_LEVEL_NONE`),
the return value will be false.

<br />

| Returns ||
|---|---|
| `boolean` | `true` if the spatializer effect is available and capable of processing the audio for the current configuration of the device, `false` otherwise. <br /> |

**See also:**

- `https://developer.android.com/reference/android/media/Spatializer#isEnabled()`

### isEnabled

Added in [API level 32](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean isEnabled ()
```

Returns whether spatialization is enabled or not.
A false value can originate for instance from the user electing to
disable the feature, or when the feature is not supported on the device (indicated
by `https://developer.android.com/reference/android/media/Spatializer#getImmersiveAudioLevel()` returning `https://developer.android.com/reference/android/media/Spatializer#SPATIALIZER_IMMERSIVE_LEVEL_NONE`).


Note that this state reflects a platform-wide state of the "desire" to use spatialization,
but availability of the audio processing is still dictated by the compatibility between
the effect and the hardware configuration, as indicated by `https://developer.android.com/reference/android/media/Spatializer#isAvailable()`.

<br />

| Returns ||
|---|---|
| `boolean` | `true` if spatialization is enabled <br /> |

**See also:**

- `https://developer.android.com/reference/android/media/Spatializer#isAvailable()`

### isHeadTrackerAvailable

Added in [API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean isHeadTrackerAvailable ()
```

Returns whether a head tracker is currently available for the audio device used by the
spatializer effect.

<br />

| Returns ||
|---|---|
| `boolean` | true if a head tracker is available and the effect is enabled, false otherwise. <br /> |

**See also:**

- `https://developer.android.com/reference/android/media/Spatializer.OnHeadTrackerAvailableListener`
- `https://developer.android.com/reference/android/media/Spatializer#addOnHeadTrackerAvailableListener(java.util.concurrent.Executor,%20android.media.Spatializer.OnHeadTrackerAvailableListener)`

### removeOnHeadTrackerAvailableListener

Added in [API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void removeOnHeadTrackerAvailableListener (Spatializer.OnHeadTrackerAvailableListener listener)
```

Removes a previously registered listener for the availability of a head tracker.

<br />

| Parameters ||
|---|---|
| `listener` | `Spatializer.OnHeadTrackerAvailableListener`: the listener previously registered with `https://developer.android.com/reference/android/media/Spatializer#addOnHeadTrackerAvailableListener(java.util.concurrent.Executor,%20android.media.Spatializer.OnHeadTrackerAvailableListener)` This value cannot be `null`. <br /> |

### removeOnSpatializerStateChangedListener

Added in [API level 32](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void removeOnSpatializerStateChangedListener (Spatializer.OnSpatializerStateChangedListener listener)
```

Removes a previously added listener for changes to the enabled state of the
`Spatializer`.

<br />

| Parameters ||
|---|---|
| `listener` | `Spatializer.OnSpatializerStateChangedListener`: the listener to receive enabled state updates. This value cannot be `null`. <br /> |

**See also:**

- `https://developer.android.com/reference/android/media/Spatializer#isEnabled()`