AudioAttributesCompat.Builder

class AudioAttributesCompat.Builder


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 will use a default usage of USAGE_MEDIA. See also AudioAttributes.Builder.

Summary

Public constructors

Constructs a new Builder with the defaults.

Constructs a new Builder from a given AudioAttributes

Public functions

AudioAttributesCompat!

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

AudioAttributesCompat.Builder!
setContentType(contentType: Int)

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

AudioAttributesCompat.Builder!
setFlags(flags: Int)

Sets the combination of flags.

AudioAttributesCompat.Builder!
setLegacyStreamType(streamType: Int)

Sets attributes as inferred from the legacy stream types.

AudioAttributesCompat.Builder!
setUsage(usage: Int)

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

Public constructors

Builder

Added in 1.1.0
Builder()

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

Builder

Added in 1.1.0
Builder(aa: AudioAttributesCompat!)

Constructs a new Builder from a given AudioAttributes

Parameters
aa: AudioAttributesCompat!

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

Public functions

build

Added in 1.1.0
fun build(): AudioAttributesCompat!

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

setContentType

Added in 1.1.0
fun setContentType(contentType: Int): AudioAttributesCompat.Builder!

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

Parameters
contentType: Int

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

Returns
AudioAttributesCompat.Builder!

the same Builder instance.

setFlags

Added in 1.1.0
fun setFlags(flags: Int): AudioAttributesCompat.Builder!

Sets the combination of flags.

This is a bitwise OR with the existing flags.

Parameters
flags: Int

a combination of FLAG_AUDIBILITY_ENFORCED, FLAG_HW_AV_SYNC.

Returns
AudioAttributesCompat.Builder!

the same Builder instance.

setLegacyStreamType

Added in 1.1.0
fun setLegacyStreamType(streamType: Int): AudioAttributesCompat.Builder!

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 setUsage and setContentType.

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

Parameters
streamType: Int

one of AudioManager.STREAM_*

Returns
AudioAttributesCompat.Builder!

this same Builder instance.