Save the date! Android Dev Summit is coming to Sunnyvale, CA on Oct 23-24, 2019.

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 unknown, or other than the ones defined.

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 music.

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

Usage value to use when the usage is unknown.

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 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.

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 notification.

static Int

Usage value to use when the usage is telephony ringtone.

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 notification for an "instant" communication such as a chat, or SMS.

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 to attract the user's attention, such as a reminder or low battery warning.

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 when the usage is for game audio.

static Int

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

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.

Public methods
open Int

open Boolean
equals(other: Any?)

open String

open Int

Returns the flags.

open Any?

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

open Int

Returns the content type.

open Int

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

open Int

Returns the usage.

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 static AudioAttributesCompat?
wrap(@NonNull aa: Any)

Creates an AudioAttributesCompat given an API 21 AudioAttributes object.

Constants

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: AudioAttributes.CONTENT_TYPE_UNKNOWN

CONTENT_TYPE_SPEECH

static val CONTENT_TYPE_SPEECH: Int

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

Value: AudioAttributes.CONTENT_TYPE_SPEECH

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_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_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

USAGE_UNKNOWN

static val USAGE_UNKNOWN: Int

Usage value to use when the usage is unknown.

Value: AudioAttributes.USAGE_UNKNOWN

USAGE_MEDIA

static val USAGE_MEDIA: Int

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

Value: AudioAttributes.USAGE_MEDIA

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: AudioAttributes.USAGE_VOICE_COMMUNICATION

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: AudioAttributes.USAGE_VOICE_COMMUNICATION_SIGNALLING

USAGE_ALARM

static val USAGE_ALARM: Int

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

Value: AudioAttributes.USAGE_ALARM

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: AudioAttributes.USAGE_NOTIFICATION

USAGE_NOTIFICATION_RINGTONE

static val USAGE_NOTIFICATION_RINGTONE: Int

Usage value to use when the usage is telephony ringtone.

Value: AudioAttributes.USAGE_NOTIFICATION_RINGTONE

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: AudioAttributes.USAGE_NOTIFICATION_COMMUNICATION_REQUEST

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: AudioAttributes.USAGE_NOTIFICATION_COMMUNICATION_INSTANT

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: AudioAttributes.USAGE_NOTIFICATION_COMMUNICATION_DELAYED

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: AudioAttributes.USAGE_NOTIFICATION_EVENT

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: AudioAttributes.USAGE_ASSISTANCE_ACCESSIBILITY

USAGE_ASSISTANCE_NAVIGATION_GUIDANCE

static val USAGE_ASSISTANCE_NAVIGATION_GUIDANCE: Int

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

Value: AudioAttributes.USAGE_ASSISTANCE_NAVIGATION_GUIDANCE

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: AudioAttributes.USAGE_ASSISTANCE_SONIFICATION

USAGE_GAME

static val USAGE_GAME: Int

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

Value: AudioAttributes.USAGE_GAME

USAGE_ASSISTANT

static val USAGE_ASSISTANT: Int

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

Value: AudioAttributes.USAGE_ASSISTANT

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: 0x1 << 0

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

Public methods

hashCode

open fun hashCode(): Int

equals

open fun equals(other: Any?): Boolean

toString

open fun toString(): String

getFlags

open fun getFlags(): Int

Returns the flags.

Return
Int: a combined mask of all flags

unwrap

@Nullable 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

Returns 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 .

getUsage

open fun getUsage(): Int

Returns the usage.

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

getLegacyStreamType

open fun getLegacyStreamType(): 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+).

Return
Int: the stream type {@see AudioManager}

wrap

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

Creates 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