AudioAttributesCompat

open class AudioAttributesCompat
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.

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 Int

open Int

Return the usage.

open Boolean
equals(other: Any?)

open String

open Int

Return a stream type passed to Builder#setLegacyStreamType(int), or -1 if no legacy stream is available

open Int

Return the flags.

open Any?

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

open Int

Return the content type.

open Int

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

open static AudioAttributesCompat?
wrap(aa: Any)

Create 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: 3

CONTENT_TYPE_MUSIC

static val CONTENT_TYPE_MUSIC: Int

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

Value: 2

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: 4

CONTENT_TYPE_SPEECH

static val CONTENT_TYPE_SPEECH: Int

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

Value: 1

CONTENT_TYPE_UNKNOWN

static val CONTENT_TYPE_UNKNOWN: Int

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

Value: 0

FLAG_AUDIBILITY_ENFORCED

static val FLAG_AUDIBILITY_ENFORCED: Int

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

Value: 1

FLAG_HW_AV_SYNC

static val FLAG_HW_AV_SYNC: Int

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

Value: 16

USAGE_ALARM

static val USAGE_ALARM: Int

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

Value: 4

USAGE_ASSISTANCE_ACCESSIBILITY

static val USAGE_ASSISTANCE_ACCESSIBILITY: Int

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

Value: 11

USAGE_ASSISTANCE_NAVIGATION_GUIDANCE

static val USAGE_ASSISTANCE_NAVIGATION_GUIDANCE: Int

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

Value: 12

USAGE_ASSISTANCE_SONIFICATION

static val USAGE_ASSISTANCE_SONIFICATION: Int

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

Value: 13

USAGE_ASSISTANT

static val USAGE_ASSISTANT: Int

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

Value: 16

USAGE_GAME

static val USAGE_GAME: Int

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

Value: 14

USAGE_MEDIA

static val USAGE_MEDIA: Int

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

Value: 1

USAGE_NOTIFICATION

static val USAGE_NOTIFICATION: Int

Usage value to use when the usage is notification. See other notification usages for more specialized uses.

Value: 5

USAGE_NOTIFICATION_COMMUNICATION_DELAYED

static val USAGE_NOTIFICATION_COMMUNICATION_DELAYED: Int

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

Value: 9

USAGE_NOTIFICATION_COMMUNICATION_INSTANT

static val USAGE_NOTIFICATION_COMMUNICATION_INSTANT: Int

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

Value: 8

USAGE_NOTIFICATION_COMMUNICATION_REQUEST

static val USAGE_NOTIFICATION_COMMUNICATION_REQUEST: Int

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

Value: 7

USAGE_NOTIFICATION_EVENT

static val USAGE_NOTIFICATION_EVENT: Int

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

Value: 10

USAGE_NOTIFICATION_RINGTONE

static val USAGE_NOTIFICATION_RINGTONE: Int

Usage value to use when the usage is telephony ringtone.

Value: 6

USAGE_UNKNOWN

static val USAGE_UNKNOWN: Int

Usage value to use when the usage is unknown.

Value: 0

USAGE_VOICE_COMMUNICATION

static val USAGE_VOICE_COMMUNICATION: Int

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

Value: 2

USAGE_VOICE_COMMUNICATION_SIGNALLING

static val USAGE_VOICE_COMMUNICATION_SIGNALLING: Int

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

Value: 3

Public methods

hashCode

open fun hashCode(): Int

getUsage

open fun getUsage(): Int

Return the usage.

Return
Int: one of the values that can be set in Builder#setUsage(int)

equals

open fun equals(other: Any?): Boolean

toString

open fun toString(): String

getLegacyStreamType

open fun getLegacyStreamType(): Int

Return a stream type passed to Builder#setLegacyStreamType(int), or -1 if no legacy stream is available

Return
Int: the stream type {@see AudioManager}

getFlags

open fun getFlags(): Int

Return the flags.

Return
Int: a combined mask of all flags

unwrap

open fun unwrap(): Any?

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

Return
Any?: the underlying AudioAttributes object or null

getContentType

open fun getContentType(): Int

Return the content type.

Return
Int: one of the values that can be set in Builder#setContentType(int)

getVolumeControlStream

open fun getVolumeControlStream(): Int

Returns the stream type matching the given attributes for volume control. Use this method to derive the stream type needed to configure the volume control slider in an with android.app.Activity#setVolumeControlStream(int).
Do not use this method to set the stream type on an audio player object (e.g. , android.media.MediaPlayer) as this is deprecated; use AudioAttributes instead.

Return
Int: a valid stream type for Activity or stream volume control that matches the attributes, or AudioManager#USE_DEFAULT_STREAM_TYPE if there isn't a direct match. Note that USE_DEFAULT_STREAM_TYPE is not a valid value for AudioManager#setStreamVolume(int, int, int).

wrap

open static fun wrap(aa: Any): AudioAttributesCompat?

Create an AudioAttributesCompat given an API 21 AudioAttributes object.

Parameters
aa Any: an instance of AudioAttributes
Return
AudioAttributesCompat?: the new AudioAttributesCompat, or null on API < 21