# SpatializerWrapper

Artifact: [androidx.media3:media3-exoplayer](https://developer.android.com/jetpack/androidx/releases/media3) [View Source](https://cs.android.com/search?q=file:androidx/media3/exoplayer/util/SpatializerWrapper.java+class:androidx.media3.exoplayer.util.SpatializerWrapper)

*** ** * ** ***


```
@RequiresApi(value = 32)
@UnstableApi
public class SpatializerWrapper
```

<br />

*** ** * ** ***

SpatializerWrapper Wraps the `https://developer.android.com/reference/android/media/Spatializer.html` in order to encapsulate its APIs within an inner class, to avoid runtime linking on devices with `API < 32`.

Also centralizes logic such as for special cases of TVs and audio formats without fixed output channel counts and for default channel masks.

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/util/SpatializerWrapper#SpatializerWrapper(android.content.Context,java.lang.Runnable,java.lang.Boolean)( @https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/android/content/Context.html context, @https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/lang/Runnable.html spatializerChangedCallback, @https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/lang/Boolean.html deviceIsTv )` Creates an instance of the Spatializer Wrapper and registers it to listen for changes. |

| ### Public methods |
|---|---|
| `boolean` | `https://developer.android.com/reference/androidx/media3/exoplayer/util/SpatializerWrapper#canBeSpatialized(androidx.media3.common.AudioAttributes,androidx.media3.common.Format)(https://developer.android.com/reference/androidx/media3/common/AudioAttributes audioAttributes, https://developer.android.com/reference/androidx/media3/common/Format format)` Returns true if the given `https://developer.android.com/reference/androidx/media3/common/AudioAttributes` and `https://developer.android.com/reference/androidx/media3/common/Format` can be spatialized. |
| `https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/java/lang/Integer.html>` | `https://developer.android.com/reference/androidx/media3/exoplayer/util/SpatializerWrapper#getSpatializedChannelMasks()()` Returns the list of channel masks that are natively supported by the `https://developer.android.com/reference/android/media/Spatializer.html`. |
| `boolean` | `https://developer.android.com/reference/androidx/media3/exoplayer/util/SpatializerWrapper#isAvailable()()` Returns true if the `https://developer.android.com/reference/android/media/Spatializer.html` is available. |
| `boolean` | `https://developer.android.com/reference/androidx/media3/exoplayer/util/SpatializerWrapper#isEnabled()()` Returns true if the `https://developer.android.com/reference/android/media/Spatializer.html` is enabled. |
| `boolean` | `https://developer.android.com/reference/androidx/media3/exoplayer/util/SpatializerWrapper#isSpatializationSupported()()` Returns true if the immersive level is not `https://developer.android.com/reference/android/media/Spatializer.html#SPATIALIZER_IMMERSIVE_LEVEL_NONE`. |
| `boolean` | `https://developer.android.com/reference/androidx/media3/exoplayer/util/SpatializerWrapper#isSupportedAvailableAndEnabled()()` A convenience method for the combined checks to see if spatialization is actually available. |
| `void` | `https://developer.android.com/reference/androidx/media3/exoplayer/util/SpatializerWrapper#release()()` |

## Public constructors

### SpatializerWrapper

```
public SpatializerWrapper(
    @Nullable Context context,
    @Nullable Runnable spatializerChangedCallback,
    @Nullable Boolean deviceIsTv
)
```

Creates an instance of the Spatializer Wrapper and registers it to listen for changes.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/android/content/Context.html context` | A context for obtaining the `https://developer.android.com/reference/android/media/Spatializer.html`. |
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/lang/Runnable.html spatializerChangedCallback` | A callback to run when the `https://developer.android.com/reference/android/media/Spatializer.html` state changes. |
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/lang/Boolean.html deviceIsTv` | Optional. Whether the device is a TV. If true, the `https://developer.android.com/reference/android/media/Spatializer.html` is not used. |

## Public methods

### canBeSpatialized

```
public boolean canBeSpatialized(AudioAttributes audioAttributes, Format format)
```

Returns true if the given `https://developer.android.com/reference/androidx/media3/common/AudioAttributes` and `https://developer.android.com/reference/androidx/media3/common/Format` can be spatialized.

Includes special logic for immersive audio formats.

### getSpatializedChannelMasks

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

Returns the list of channel masks that are natively supported by the `https://developer.android.com/reference/android/media/Spatializer.html`.

On API 36+, this is delegated to the `https://developer.android.com/reference/android/media/Spatializer.html#getSpatializedChannelMasks()`. On API 32-35, the default channel mask is 5.1.

### isAvailable

```
public boolean isAvailable()
```

Returns true if the `https://developer.android.com/reference/android/media/Spatializer.html` is available.

This is delegated to `https://developer.android.com/reference/android/media/Spatializer.html#isAvailable()`.

### isEnabled

```
public boolean isEnabled()
```

Returns true if the `https://developer.android.com/reference/android/media/Spatializer.html` is enabled.

This is delegated to `https://developer.android.com/reference/android/media/Spatializer.html#isEnabled()`.

### isSpatializationSupported

```
public boolean isSpatializationSupported()
```

Returns true if the immersive level is not `https://developer.android.com/reference/android/media/Spatializer.html#SPATIALIZER_IMMERSIVE_LEVEL_NONE`.

### isSupportedAvailableAndEnabled

```
public boolean isSupportedAvailableAndEnabled()
```

A convenience method for the combined checks to see if spatialization is actually available.

### release

```
public void release()
```