# AudioAttributes

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

*** ** * ** ***


```
public final class AudioAttributes
```

<br />

*** ** * ** ***

Attributes for audio playback, which configure the underlying platform `https://developer.android.com/reference/android/media/AudioTrack.html`.

To set the audio attributes, create an instance using the `https://developer.android.com/reference/androidx/media3/common/AudioAttributes.Builder` and either pass it to the player or send a message of type `Renderer#MSG_SET_AUDIO_ATTRIBUTES` to the audio renderers.

This class is based on `https://developer.android.com/reference/android/media/AudioAttributes.html`, but can be used on all supported API versions.

## Summary

| ### Nested types |
|---|
| `public final class https://developer.android.com/reference/androidx/media3/common/AudioAttributes.AudioAttributesV21` **This class is deprecated.** Use `https://developer.android.com/reference/android/media/AudioAttributes.html`. <br /> |
| `public final class https://developer.android.com/reference/androidx/media3/common/AudioAttributes.Builder` Builder for `https://developer.android.com/reference/androidx/media3/common/AudioAttributes`. |

| ### Constants |
|---|---|
| `static final https://developer.android.com/reference/androidx/media3/common/AudioAttributes` | `https://developer.android.com/reference/androidx/media3/common/AudioAttributes#DEFAULT()` The default audio attributes, where the content type is `https://developer.android.com/reference/androidx/media3/common/C#AUDIO_CONTENT_TYPE_UNKNOWN()`, usage is `https://developer.android.com/reference/androidx/media3/common/C#USAGE_MEDIA()`, capture policy is `https://developer.android.com/reference/androidx/media3/common/C#ALLOW_CAPTURE_BY_ALL()` and no flags are set. |

| ### Public fields |
|---|---|
| `final int` | `@https://developer.android.com/reference/androidx/media3/common/C.AudioAllowedCapturePolicy https://developer.android.com/reference/androidx/media3/common/AudioAttributes#allowedCapturePolicy()` The `https://developer.android.com/reference/androidx/media3/common/C.AudioAllowedCapturePolicy`. |
| `final int` | `@https://developer.android.com/reference/androidx/media3/common/C.AudioContentType https://developer.android.com/reference/androidx/media3/common/AudioAttributes#contentType()` The `https://developer.android.com/reference/androidx/media3/common/C.AudioContentType`. |
| `final int` | `@https://developer.android.com/reference/androidx/media3/common/C.AudioFlags https://developer.android.com/reference/androidx/media3/common/AudioAttributes#flags()` The `https://developer.android.com/reference/androidx/media3/common/C.AudioFlags`. |
| `final boolean` | `@https://developer.android.com/reference/androidx/media3/common/util/UnstableApi https://developer.android.com/reference/androidx/media3/common/AudioAttributes#hapticChannelsMuted()` Whether haptic channels are muted. |
| `final boolean` | `@https://developer.android.com/reference/androidx/media3/common/util/UnstableApi https://developer.android.com/reference/androidx/media3/common/AudioAttributes#isContentSpatialized()` Whether the content is spatialized. |
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/android/media/AudioAttributes.html` | `https://developer.android.com/reference/androidx/media3/common/AudioAttributes#platformAudioAttributes()` |
| `final int` | `@https://developer.android.com/reference/androidx/media3/common/C.SpatializationBehavior https://developer.android.com/reference/androidx/media3/common/AudioAttributes#spatializationBehavior()` The `https://developer.android.com/reference/androidx/media3/common/C.SpatializationBehavior`. |
| `final int` | `@https://developer.android.com/reference/androidx/media3/common/C.AudioUsage https://developer.android.com/reference/androidx/media3/common/AudioAttributes#usage()` The `https://developer.android.com/reference/androidx/media3/common/C.AudioUsage`. |

| ### Public methods |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/AudioAttributes.Builder` | `@https://developer.android.com/reference/androidx/media3/common/util/UnstableApi https://developer.android.com/reference/androidx/media3/common/AudioAttributes#buildUpon()()` Create new AudioAttributes based on an existing instance. |
| `boolean` | `https://developer.android.com/reference/androidx/media3/common/AudioAttributes#equals(java.lang.Object)(@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/lang/Object.html obj)` |
| `static https://developer.android.com/reference/androidx/media3/common/AudioAttributes` | `@https://developer.android.com/reference/androidx/media3/common/util/UnstableApi https://developer.android.com/reference/androidx/media3/common/AudioAttributes#fromBundle(android.os.Bundle)(https://developer.android.com/reference/android/os/Bundle.html bundle)` Restores a `AudioAttributes` from a `https://developer.android.com/reference/android/os/Bundle.html`. |
| `static https://developer.android.com/reference/androidx/media3/common/AudioAttributes` | `https://developer.android.com/reference/androidx/media3/common/AudioAttributes#fromPlatformAudioAttributes(android.media.AudioAttributes)(https://developer.android.com/reference/android/media/AudioAttributes.html audioAttributes)` Creates a new instance from the provided `https://developer.android.com/reference/android/media/AudioAttributes.html`. |
| `https://developer.android.com/reference/androidx/media3/common/AudioAttributes.AudioAttributesV21` | `[getAudioAttributesV21](https://developer.android.com/reference/androidx/media3/common/AudioAttributes#getAudioAttributesV21())()` **This method is deprecated.** Use `https://developer.android.com/reference/androidx/media3/common/AudioAttributes#getPlatformAudioAttributes()` <br /> |
| `https://developer.android.com/reference/android/media/AudioAttributes.html` | `https://developer.android.com/reference/androidx/media3/common/AudioAttributes#getPlatformAudioAttributes()()` Returns a `https://developer.android.com/reference/android/media/AudioAttributes.html` from this instance. |
| `int` | `@https://developer.android.com/reference/androidx/media3/common/util/UnstableApi @https://developer.android.com/reference/androidx/media3/common/C.StreamType [getStreamType](https://developer.android.com/reference/androidx/media3/common/AudioAttributes#getStreamType())()` **This method is deprecated.** Use `https://developer.android.com/reference/androidx/media3/common/AudioAttributes#getVolumeControlStream()` instead. <br /> |
| `int` | `@https://developer.android.com/reference/androidx/media3/common/C.StreamType https://developer.android.com/reference/androidx/media3/common/AudioAttributes#getVolumeControlStream()()` Returns the `https://developer.android.com/reference/androidx/media3/common/C.StreamType` for these audio attributes. |
| `int` | `https://developer.android.com/reference/androidx/media3/common/AudioAttributes#hashCode()()` |
| `https://developer.android.com/reference/android/os/Bundle.html` | `@https://developer.android.com/reference/androidx/media3/common/util/UnstableApi https://developer.android.com/reference/androidx/media3/common/AudioAttributes#toBundle()()` |

## Constants

### DEFAULT

```
public static final AudioAttributes DEFAULT
```

The default audio attributes, where the content type is `https://developer.android.com/reference/androidx/media3/common/C#AUDIO_CONTENT_TYPE_UNKNOWN()`, usage is `https://developer.android.com/reference/androidx/media3/common/C#USAGE_MEDIA()`, capture policy is `https://developer.android.com/reference/androidx/media3/common/C#ALLOW_CAPTURE_BY_ALL()` and no flags are set.

## Public fields

### allowedCapturePolicy

```
@C.AudioAllowedCapturePolicy
public final int allowedCapturePolicy
```

The `https://developer.android.com/reference/androidx/media3/common/C.AudioAllowedCapturePolicy`.

### contentType

```
@C.AudioContentType
public final int contentType
```

The `https://developer.android.com/reference/androidx/media3/common/C.AudioContentType`.

### flags

```
@C.AudioFlags
public final int flags
```

The `https://developer.android.com/reference/androidx/media3/common/C.AudioFlags`.

### hapticChannelsMuted

```
@UnstableApi
public final boolean hapticChannelsMuted
```

Whether haptic channels are muted.

### isContentSpatialized

```
@UnstableApi
public final boolean isContentSpatialized
```

Whether the content is spatialized.

### platformAudioAttributes

```
public @Nullable AudioAttributes platformAudioAttributes
```

### spatializationBehavior

```
@C.SpatializationBehavior
public final int spatializationBehavior
```

The `https://developer.android.com/reference/androidx/media3/common/C.SpatializationBehavior`.

### usage

```
@C.AudioUsage
public final int usage
```

The `https://developer.android.com/reference/androidx/media3/common/C.AudioUsage`.

## Public methods

### buildUpon

```
@UnstableApi
public AudioAttributes.Builder buildUpon()
```

Create new AudioAttributes based on an existing instance.

### equals

```
public boolean equals(@Nullable Object obj)
```

### fromBundle

```
@UnstableApi
public static AudioAttributes fromBundle(Bundle bundle)
```

Restores a `AudioAttributes` from a `https://developer.android.com/reference/android/os/Bundle.html`.

### fromPlatformAudioAttributes

```
public static AudioAttributes fromPlatformAudioAttributes(AudioAttributes audioAttributes)
```

Creates a new instance from the provided `https://developer.android.com/reference/android/media/AudioAttributes.html`.

### getAudioAttributesV21

```
public AudioAttributes.AudioAttributesV21 [getAudioAttributesV21](https://developer.android.com/reference/androidx/media3/common/AudioAttributes#getAudioAttributesV21())()
```

> [!CAUTION]
> **This method is deprecated.**   
>
> Use `https://developer.android.com/reference/androidx/media3/common/AudioAttributes#getPlatformAudioAttributes()`

### getPlatformAudioAttributes

```
public AudioAttributes getPlatformAudioAttributes()
```

Returns a `https://developer.android.com/reference/android/media/AudioAttributes.html` from this instance.

Some fields are ignored if the corresponding `https://developer.android.com/reference/android/media/AudioAttributes.Builder.html` setter is not available on the current API level.

### getStreamType

```
@UnstableApi
@C.StreamType
public int [getStreamType](https://developer.android.com/reference/androidx/media3/common/AudioAttributes#getStreamType())()
```

> [!CAUTION]
> **This method is deprecated.**   
>
> Use `https://developer.android.com/reference/androidx/media3/common/AudioAttributes#getVolumeControlStream()` instead.

### getVolumeControlStream

```
@C.StreamType
public int getVolumeControlStream()
```

Returns the `https://developer.android.com/reference/androidx/media3/common/C.StreamType` for these audio attributes.

### hashCode

```
public int hashCode()
```

### toBundle

```
@UnstableApi
public Bundle toBundle()
```