Android 12 Developer Preview is here! Try it out, and give us your feedback!

AudioAttributesCompat

open class AudioAttributesCompat : VersionedParcelable
kotlin.Any
   ↳ androidx.media.AudioAttributesCompat

A class to encapsulate a collection of attributes describing information about an audio stream.

AudioAttributesCompat supersede the notion of stream types (see for instance AudioManager#STREAM_MUSIC or AudioManager#STREAM_ALARM) for defining the behavior of audio playback. Attributes allow an application to specify more information than is conveyed in a stream type by allowing the application to define:

  • usage: "why" you are playing a sound, what is this sound used for. This is achieved with the "usage" information. Examples of usage are USAGE_MEDIA and . These two examples are the closest to stream types, but more detailed use cases are available. Usage information is more expressive than a stream type, and allows certain platforms or routing policies to use this information for more refined volume or routing decisions. Usage is the most important information to supply in AudioAttributesCompat and it is recommended to build any instance with this information supplied, see AudioAttributesCompat.Builder for exceptions.
  • content type: "what" you are playing. The content type expresses the general category of the content. This information is optional. But in case it is known (for instance for a movie streaming service or CONTENT_TYPE_MUSIC for a music playback application) this information might be used by the audio framework to selectively configure some audio post-processing blocks.
  • flags: "how" is playback to be affected, see the flag definitions for the specific playback behaviors they control.

AudioAttributesCompat instance is built through its builder, . Also see android.media.AudioAttributes for the framework implementation of this class.

Summary

Nested classes
open

Builder class for AudioAttributesCompat objects.

Constants
static Int

Content type value to use when the content type is a soundtrack, typically accompanying a movie or TV program.

static Int

Content type value to use when the content type is music.

static Int

Content type value to use when the content type is a sound used to accompany a user action, such as a beep or sound effect expressing a key click, or event, such as the type of a sound for a bonus being received in a game.

static Int

Content type value to use when the content type is speech.

static Int

Content type value to use when the content type is unknown, or other than the ones defined.

static Int

Flag defining a behavior where the audibility of the sound will be ensured by the system.

static Int

Flag requesting the use of an output stream supporting hardware A/V synchronization.

static Int

Usage value to use when the usage is an alarm (e.g. wake-up alarm).

static Int

Usage value to use when the usage is for accessibility, such as with a screen reader.

static Int

Usage value to use when the usage is driving or navigation directions.

static Int

Usage value to use when the usage is sonification, such as with user interface sounds.

static Int

Usage value to use for audio responses to user queries, audio instructions or help utterances.

static Int

Usage value to use when the usage is for game audio.

static Int

Usage value to use when the usage is media, such as music, or movie soundtracks.

static Int

Usage value to use when the usage is notification.

static Int

Usage value to use when the usage is notification for a non-immediate type of communication such as e-mail.

static Int

Usage value to use when the usage is notification for an "instant" communication such as a chat, or SMS.

static Int

Usage value to use when the usage is a request to enter/end a communication, such as a VoIP communication or video-conference.

static Int

Usage value to use when the usage is to attract the user's attention, such as a reminder or low battery warning.

static Int

Usage value to use when the usage is telephony ringtone.

static Int

Usage value to use when the usage is unknown.

static Int

Usage value to use when the usage is voice communications, such as telephony or VoIP.

static Int

Usage value to use when the usage is in-call signalling, such as with a "busy" beep, or DTMF tones.

Public methods
open Boolean
equals(other: Any?)

open Int

Returns the content type.

open Int

Returns the flags.

open Int

Returns a stream type passed to Builder#setLegacyStreamType(int), or best guessing from flags and usage, or -1 if there is no converting logic in framework side (API 21+).

open Int

Returns the usage.

open Int

Returns the stream type matching the given attributes for volume control.

open Int

open String

open Any?

If the current SDK level is 21 or higher, return the AudioAttributes object inside this AudioAttributesCompat.

open static AudioAttributesCompat?
wrap(@NonNull aa: Any)

Creates an AudioAttributesCompat given an API 21 AudioAttributes object.

Constants

CONTENT_TYPE_MOVIE

static val CONTENT_TYPE_MOVIE: Int

Content type value to use when the content type is a soundtrack, typically accompanying a movie or TV program.

Value: AudioAttributes.CONTENT_TYPE_MOVIE

CONTENT_TYPE_MUSIC

static val CONTENT_TYPE_MUSIC: Int

Content type value to use when the content type is music.

Value: AudioAttributes.CONTENT_TYPE_MUSIC

CONTENT_TYPE_SONIFICATION

static val CONTENT_TYPE_SONIFICATION: Int

Content type value to use when the content type is a sound used to accompany a user action, such as a beep or sound effect expressing a key click, or event, such as the type of a sound for a bonus being received in a game. These sounds are mostly synthesized or short Foley sounds.

Value: AudioAttributes.CONTENT_TYPE_SONIFICATION

CONTENT_TYPE_SPEECH

static val CONTENT_TYPE_SPEECH: Int