# AudioAttributesCompat.Builder

Artifact: [androidx.media:media](https://developer.android.com/jetpack/androidx/releases/media) [View Source](https://cs.android.com/search?q=file:androidx/media/AudioAttributesCompat.java+class:androidx.media.AudioAttributesCompat.Builder) Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/media#1.1.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/media#1.8.0)

*** ** * ** ***


```
class AudioAttributesCompat.Builder
```

<br />

*** ** * ** ***

> [!CAUTION]
> **This class is deprecated.**   
>
> androidx.media is deprecated. Please migrate to [androidx.media3](https://developer.android.com/media/media3).

Builder class for `https://developer.android.com/reference/kotlin/androidx/media/AudioAttributesCompat` objects.

example:

```kotlin
new AudioAttributes.Builder()
.setUsage(AudioAttributes.USAGE_MEDIA)
.setContentType(AudioAttributes.CONTENT_TYPE_MUSIC)
.build();
```

By default all types of information (usage, content type, flags) conveyed by an `
AudioAttributesCompat` instance are set to "unknown". Unknown information will be interpreted as a default value that is dependent on the context of use, for instance a `https://developer.android.com/reference/android/media/MediaPlayer.html` will use a default usage of `https://developer.android.com/reference/kotlin/androidx/media/AudioAttributesCompat#USAGE_MEDIA()`. See also `https://developer.android.com/reference/android/media/AudioAttributes.Builder.html`.

## Summary

| ### Public constructors |
|---|
| `[Builder](https://developer.android.com/reference/kotlin/androidx/media/AudioAttributesCompat.Builder#Builder())()` **This function is deprecated.** Deprecated in Java |
| `[Builder](https://developer.android.com/reference/kotlin/androidx/media/AudioAttributesCompat.Builder#Builder(androidx.media.AudioAttributesCompat))(aa: https://developer.android.com/reference/kotlin/androidx/media/AudioAttributesCompat!)` **This function is deprecated.** Deprecated in Java |

| ### Public functions |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/media/AudioAttributesCompat!` | `[build](https://developer.android.com/reference/kotlin/androidx/media/AudioAttributesCompat.Builder#build())()` **This function is deprecated.** Deprecated in Java |
| `https://developer.android.com/reference/kotlin/androidx/media/AudioAttributesCompat.Builder!` | `[setContentType](https://developer.android.com/reference/kotlin/androidx/media/AudioAttributesCompat.Builder#setContentType(int))(contentType: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` **This function is deprecated.** Deprecated in Java |
| `https://developer.android.com/reference/kotlin/androidx/media/AudioAttributesCompat.Builder!` | `[setFlags](https://developer.android.com/reference/kotlin/androidx/media/AudioAttributesCompat.Builder#setFlags(int))(flags: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` **This function is deprecated.** Deprecated in Java |
| `https://developer.android.com/reference/kotlin/androidx/media/AudioAttributesCompat.Builder!` | `[setLegacyStreamType](https://developer.android.com/reference/kotlin/androidx/media/AudioAttributesCompat.Builder#setLegacyStreamType(int))(streamType: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` **This function is deprecated.** Deprecated in Java |
| `https://developer.android.com/reference/kotlin/androidx/media/AudioAttributesCompat.Builder!` | `[setUsage](https://developer.android.com/reference/kotlin/androidx/media/AudioAttributesCompat.Builder#setUsage(int))(usage: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` **This function is deprecated.** Deprecated in Java |

## Public constructors

### Builder

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/media#1.1.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/media#1.8.0)

```
[Builder](https://developer.android.com/reference/kotlin/androidx/media/AudioAttributesCompat.Builder#Builder())()
```

> [!CAUTION]
> **This function is deprecated.**   
> Deprecated in Java

Constructs a new Builder with the defaults. By default, usage and content type are respectively `https://developer.android.com/reference/kotlin/androidx/media/AudioAttributesCompat#USAGE_UNKNOWN()` and `https://developer.android.com/reference/kotlin/androidx/media/AudioAttributesCompat#CONTENT_TYPE_UNKNOWN()`, and flags are 0. It is recommended to configure the usage (with `https://developer.android.com/reference/kotlin/androidx/media/AudioAttributesCompat.Builder#setUsage(int)`) or deriving attributes from a legacy stream type (with `https://developer.android.com/reference/kotlin/androidx/media/AudioAttributesCompat.Builder#setLegacyStreamType(int)`) before calling `https://developer.android.com/reference/kotlin/androidx/media/AudioAttributesCompat.Builder#build()` to override any default playback behavior in terms of routing and volume management.

### Builder

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/media#1.1.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/media#1.8.0)

```
[Builder](https://developer.android.com/reference/kotlin/androidx/media/AudioAttributesCompat.Builder#Builder(androidx.media.AudioAttributesCompat))(aa: AudioAttributesCompat!)
```

> [!CAUTION]
> **This function is deprecated.**   
> Deprecated in Java

Constructs a new Builder from a given AudioAttributes

| Parameters |
|---|---|
| `aa: https://developer.android.com/reference/kotlin/androidx/media/AudioAttributesCompat!` | the AudioAttributesCompat object whose data will be reused in the new Builder. |

## Public functions

### build

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/media#1.1.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/media#1.8.0)

```
fun [build](https://developer.android.com/reference/kotlin/androidx/media/AudioAttributesCompat.Builder#build())(): AudioAttributesCompat!
```

> [!CAUTION]
> **This function is deprecated.**   
> Deprecated in Java

Combines all of the attributes that have been set and return a new `https://developer.android.com/reference/kotlin/androidx/media/AudioAttributesCompat` object.

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/media/AudioAttributesCompat!` | a new `https://developer.android.com/reference/kotlin/androidx/media/AudioAttributesCompat` object |

### setContentType

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/media#1.1.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/media#1.8.0)

```
fun [setContentType](https://developer.android.com/reference/kotlin/androidx/media/AudioAttributesCompat.Builder#setContentType(int))(contentType: Int): AudioAttributesCompat.Builder!
```

> [!CAUTION]
> **This function is deprecated.**   
> Deprecated in Java

Sets the attribute describing the content type of the audio signal, such as speech, or music.

| Parameters |
|---|---|
| `contentType: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | the content type values, one of `https://developer.android.com/reference/kotlin/androidx/media/AudioAttributesCompat#CONTENT_TYPE_MOVIE()`, `https://developer.android.com/reference/kotlin/androidx/media/AudioAttributesCompat#CONTENT_TYPE_MUSIC()`, `https://developer.android.com/reference/kotlin/androidx/media/AudioAttributesCompat#CONTENT_TYPE_SONIFICATION()`, `https://developer.android.com/reference/kotlin/androidx/media/AudioAttributesCompat#CONTENT_TYPE_SPEECH()`, `https://developer.android.com/reference/kotlin/androidx/media/AudioAttributesCompat#CONTENT_TYPE_UNKNOWN()`. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/media/AudioAttributesCompat.Builder!` | the same Builder instance. |

### setFlags

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/media#1.1.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/media#1.8.0)

```
fun [setFlags](https://developer.android.com/reference/kotlin/androidx/media/AudioAttributesCompat.Builder#setFlags(int))(flags: Int): AudioAttributesCompat.Builder!
```

> [!CAUTION]
> **This function is deprecated.**   
> Deprecated in Java

Sets the combination of flags.

This is a bitwise OR with the existing flags.

| Parameters |
|---|---|
| `flags: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | a combination of `https://developer.android.com/reference/kotlin/androidx/media/AudioAttributesCompat#FLAG_AUDIBILITY_ENFORCED()`, `https://developer.android.com/reference/kotlin/androidx/media/AudioAttributesCompat#FLAG_HW_AV_SYNC()`. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/media/AudioAttributesCompat.Builder!` | the same Builder instance. |

### setLegacyStreamType

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/media#1.1.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/media#1.8.0)

```
fun [setLegacyStreamType](https://developer.android.com/reference/kotlin/androidx/media/AudioAttributesCompat.Builder#setLegacyStreamType(int))(streamType: Int): AudioAttributesCompat.Builder!
```

> [!CAUTION]
> **This function is deprecated.**   
> Deprecated in Java

Sets attributes as inferred from the legacy stream types.

Warning: do not use this method in combination with setting any other attributes such as usage, content type, or flags, as this method will overwrite (the more accurate) information describing the use case previously set in the Builder. In general, avoid using it and prefer setting usage and content type directly with `https://developer.android.com/reference/kotlin/androidx/media/AudioAttributesCompat.Builder#setUsage(int)` and `https://developer.android.com/reference/kotlin/androidx/media/AudioAttributesCompat.Builder#setContentType(int)`.

Use this method when building an `https://developer.android.com/reference/android/media/AudioAttributes.html` instance to initialize some of the attributes by information derived from a legacy stream type.

| Parameters |
|---|---|
| `streamType: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | one of `AudioManager.STREAM_*` |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/media/AudioAttributesCompat.Builder!` | this same Builder instance. |

### setUsage

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/media#1.1.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/media#1.8.0)

```
fun [setUsage](https://developer.android.com/reference/kotlin/androidx/media/AudioAttributesCompat.Builder#setUsage(int))(usage: Int): AudioAttributesCompat.Builder!
```

> [!CAUTION]
> **This function is deprecated.**   
> Deprecated in Java

Sets the attribute describing what is the intended use of the the audio signal, such as alarm or ringtone.

| Parameters |
|---|---|
| `usage: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | one of `https://developer.android.com/reference/kotlin/androidx/media/AudioAttributesCompat#USAGE_UNKNOWN()`, `https://developer.android.com/reference/kotlin/androidx/media/AudioAttributesCompat#USAGE_MEDIA()`, `https://developer.android.com/reference/kotlin/androidx/media/AudioAttributesCompat#USAGE_VOICE_COMMUNICATION()`, `https://developer.android.com/reference/kotlin/androidx/media/AudioAttributesCompat#USAGE_VOICE_COMMUNICATION_SIGNALLING()`, `https://developer.android.com/reference/kotlin/androidx/media/AudioAttributesCompat#USAGE_ALARM()`, `https://developer.android.com/reference/kotlin/androidx/media/AudioAttributesCompat#USAGE_NOTIFICATION()`, `https://developer.android.com/reference/kotlin/androidx/media/AudioAttributesCompat#USAGE_NOTIFICATION_RINGTONE()`, `https://developer.android.com/reference/kotlin/androidx/media/AudioAttributesCompat#USAGE_NOTIFICATION_COMMUNICATION_REQUEST()`, `https://developer.android.com/reference/kotlin/androidx/media/AudioAttributesCompat#USAGE_NOTIFICATION_COMMUNICATION_INSTANT()`, `https://developer.android.com/reference/kotlin/androidx/media/AudioAttributesCompat#USAGE_NOTIFICATION_COMMUNICATION_DELAYED()`, `https://developer.android.com/reference/kotlin/androidx/media/AudioAttributesCompat#USAGE_NOTIFICATION_EVENT()`, `https://developer.android.com/reference/kotlin/androidx/media/AudioAttributesCompat#USAGE_ASSISTANT()`, `https://developer.android.com/reference/kotlin/androidx/media/AudioAttributesCompat#USAGE_ASSISTANCE_ACCESSIBILITY()`, `https://developer.android.com/reference/kotlin/androidx/media/AudioAttributesCompat#USAGE_ASSISTANCE_NAVIGATION_GUIDANCE()`, `https://developer.android.com/reference/kotlin/androidx/media/AudioAttributesCompat#USAGE_ASSISTANCE_SONIFICATION()`, `https://developer.android.com/reference/kotlin/androidx/media/AudioAttributesCompat#USAGE_GAME()`. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/media/AudioAttributesCompat.Builder!` | the same Builder instance. |