public class

AudioAttributesCompat.Builder

extends java.lang.Object

 java.lang.Object

↳androidx.media3.session.legacy.AudioAttributesCompat.Builder

Overview

Builder class for AudioAttributesCompat objects.

example:

 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 android.media.MediaPlayer will use a default usage of AudioAttributesCompat.USAGE_MEDIA. See also .

Summary

Constructors
publicBuilder()

Constructs a new Builder with the defaults.

publicBuilder(AudioAttributesCompat aa)

Constructs a new Builder from a given AudioAttributes

Methods
public AudioAttributesCompatbuild()

Combines all of the attributes that have been set and return a new AudioAttributesCompat object.

public AudioAttributesCompat.BuildersetContentType(int contentType)

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

public AudioAttributesCompat.BuildersetFlags(int flags)

Sets the combination of flags.

public AudioAttributesCompat.BuildersetLegacyStreamType(int streamType)

Sets attributes as inferred from the legacy stream types.

public AudioAttributesCompat.BuildersetUsage(int usage)

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

from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructors

public Builder()

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

public Builder(AudioAttributesCompat aa)

Constructs a new Builder from a given AudioAttributes

Parameters:

aa: the AudioAttributesCompat object whose data will be reused in the new Builder.

Methods

public AudioAttributesCompat build()

Combines all of the attributes that have been set and return a new AudioAttributesCompat object.

Returns:

a new AudioAttributesCompat object

public AudioAttributesCompat.Builder setUsage(int usage)

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

Parameters:

usage: one of AudioAttributesCompat.USAGE_UNKNOWN, AudioAttributesCompat.USAGE_MEDIA, AudioAttributesCompat.USAGE_VOICE_COMMUNICATION, AudioAttributesCompat.USAGE_VOICE_COMMUNICATION_SIGNALLING, AudioAttributesCompat.USAGE_ALARM, AudioAttributesCompat.USAGE_NOTIFICATION, AudioAttributesCompat.USAGE_NOTIFICATION_RINGTONE, AudioAttributesCompat.USAGE_NOTIFICATION_COMMUNICATION_REQUEST, AudioAttributesCompat.USAGE_NOTIFICATION_COMMUNICATION_INSTANT, AudioAttributesCompat.USAGE_NOTIFICATION_COMMUNICATION_DELAYED, AudioAttributesCompat.USAGE_NOTIFICATION_EVENT, AudioAttributesCompat.USAGE_ASSISTANT, AudioAttributesCompat.USAGE_ASSISTANCE_ACCESSIBILITY, AudioAttributesCompat.USAGE_ASSISTANCE_NAVIGATION_GUIDANCE, AudioAttributesCompat.USAGE_ASSISTANCE_SONIFICATION, AudioAttributesCompat.USAGE_GAME.

Returns:

the same Builder instance.

public AudioAttributesCompat.Builder setContentType(int contentType)

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

Parameters:

contentType: the content type values, one of AudioAttributesCompat.CONTENT_TYPE_MOVIE, AudioAttributesCompat.CONTENT_TYPE_MUSIC, AudioAttributesCompat.CONTENT_TYPE_SONIFICATION, AudioAttributesCompat.CONTENT_TYPE_SPEECH, AudioAttributesCompat.CONTENT_TYPE_UNKNOWN.

Returns:

the same Builder instance.

public AudioAttributesCompat.Builder setFlags(int flags)

Sets the combination of flags.

This is a bitwise OR with the existing flags.

Parameters:

flags: a combination of AudioAttributesCompat.FLAG_AUDIBILITY_ENFORCED, AudioAttributesCompat.FLAG_HW_AV_SYNC.

Returns:

the same Builder instance.

public AudioAttributesCompat.Builder setLegacyStreamType(int streamType)

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 AudioAttributesCompat.Builder.setUsage(int) and AudioAttributesCompat.Builder.setContentType(int).

Use this method when building an AudioAttributes instance to initialize some of the attributes by information derived from a legacy stream type.

Parameters:

streamType: one of AudioManager.STREAM_*

Returns:

this same Builder instance.