Android APIs
public final class

AudioAttributes

extends Object
implements Parcelable
java.lang.Object
   ↳ android.media.AudioAttributes

Class Overview

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

AudioAttributes supersede the notion of stream types (see for instance STREAM_MUSIC or 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 USAGE_ALARM. 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 AudioAttributes and it is recommended to build any instance with this information supplied, see AudioAttributes.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 CONTENT_TYPE_MOVIE 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.

AudioAttributes are used for example in one of the AudioTrack constructors (see AudioTrack(AudioAttributes, AudioFormat, int, int, int)), to configure a MediaPlayer (see setAudioAttributes(AudioAttributes) or a Notification (see audioAttributes). An AudioAttributes instance is built through its builder, AudioAttributes.Builder.

Summary

Nested Classes
class AudioAttributes.Builder Builder class for AudioAttributes objects. 
Constants
int CONTENT_TYPE_MOVIE Content type value to use when the content type is a soundtrack, typically accompanying a movie or TV program.
int CONTENT_TYPE_MUSIC Content type value to use when the content type is music.
int CONTENT_TYPE_SONIFICATION 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.
int CONTENT_TYPE_SPEECH Content type value to use when the content type is speech.
int CONTENT_TYPE_UNKNOWN Content type value to use when the content type is unknown, or other than the ones defined.
int FLAG_AUDIBILITY_ENFORCED Flag defining a behavior where the audibility of the sound will be ensured by the system.
int FLAG_HW_AV_SYNC Flag requesting the use of an output stream supporting hardware A/V synchronization.
int USAGE_ALARM Usage value to use when the usage is an alarm (e.g.
int USAGE_ASSISTANCE_ACCESSIBILITY Usage value to use when the usage is for accessibility, such as with a screen reader.
int USAGE_ASSISTANCE_NAVIGATION_GUIDANCE Usage value to use when the usage is driving or navigation directions.
int USAGE_ASSISTANCE_SONIFICATION Usage value to use when the usage is sonification, such as with user interface sounds.
int USAGE_GAME Usage value to use when the usage is for game audio.
int USAGE_MEDIA Usage value to use when the usage is media, such as music, or movie soundtracks.
int USAGE_NOTIFICATION Usage value to use when the usage is notification.
int USAGE_NOTIFICATION_COMMUNICATION_DELAYED Usage value to use when the usage is notification for a non-immediate type of communication such as e-mail.
int USAGE_NOTIFICATION_COMMUNICATION_INSTANT Usage value to use when the usage is notification for an "instant" communication such as a chat, or SMS.
int USAGE_NOTIFICATION_COMMUNICATION_REQUEST Usage value to use when the usage is a request to enter/end a communication, such as a VoIP communication or video-conference.
int USAGE_NOTIFICATION_EVENT Usage value to use when the usage is to attract the user's attention, such as a reminder or low battery warning.
int USAGE_NOTIFICATION_RINGTONE Usage value to use when the usage is telephony ringtone.
int USAGE_UNKNOWN Usage value to use when the usage is unknown.
int USAGE_VOICE_COMMUNICATION Usage value to use when the usage is voice communications, such as telephony or VoIP.
int USAGE_VOICE_COMMUNICATION_SIGNALLING Usage value to use when the usage is in-call signalling, such as with a "busy" beep, or DTMF tones.
[Expand]
Inherited Constants
From interface android.os.Parcelable
Fields
public static final Creator<AudioAttributes> CREATOR
Public Methods
int describeContents()
Describe the kinds of special objects contained in this Parcelable's marshalled representation.
boolean equals(Object o)
Compares this instance with the specified object and indicates if they are equal.
int getContentType()
Return the content type.
int getFlags()
Return the flags.
int getUsage()
Return the usage.
int hashCode()
Returns an integer hash code for this object.
String toString()
Returns a string containing a concise, human-readable description of this object.
void writeToParcel(Parcel dest, int flags)
Flatten this object in to a Parcel.
[Expand]
Inherited Methods
From class java.lang.Object
From interface android.os.Parcelable

Constants

public static final int CONTENT_TYPE_MOVIE

Added in API level 21

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

Constant Value: 3 (0x00000003)

public static final int CONTENT_TYPE_MUSIC

Added in API level 21

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

Constant Value: 2 (0x00000002)

public static final int CONTENT_TYPE_SONIFICATION

Added in API level 21

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.

Constant Value: 4 (0x00000004)

public static final int CONTENT_TYPE_SPEECH

Added in API level 21

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

Constant Value: 1 (0x00000001)

public static final int CONTENT_TYPE_UNKNOWN

Added in API level 21

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

Constant Value: 0 (0x00000000)

public static final int FLAG_AUDIBILITY_ENFORCED

Added in API level 21

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

Constant Value: 1 (0x00000001)

public static final int FLAG_HW_AV_SYNC

Added in API level 21

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

Constant Value: 16 (0x00000010)

public static final int USAGE_ALARM

Added in API level 21

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

Constant Value: 4 (0x00000004)

public static final int USAGE_ASSISTANCE_ACCESSIBILITY

Added in API level 21

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

Constant Value: 11 (0x0000000b)

public static final int USAGE_ASSISTANCE_NAVIGATION_GUIDANCE

Added in API level 21

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

Constant Value: 12 (0x0000000c)

public static final int USAGE_ASSISTANCE_SONIFICATION

Added in API level 21

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

Constant Value: 13 (0x0000000d)

public static final int USAGE_GAME

Added in API level 21

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

Constant Value: 14 (0x0000000e)

public static final int USAGE_MEDIA

Added in API level 21

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

Constant Value: 1 (0x00000001)

public static final int USAGE_NOTIFICATION

Added in API level 21

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

Constant Value: 5 (0x00000005)

public static final int USAGE_NOTIFICATION_COMMUNICATION_DELAYED

Added in API level 21

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

Constant Value: 9 (0x00000009)

public static final int USAGE_NOTIFICATION_COMMUNICATION_INSTANT

Added in API level 21

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

Constant Value: 8 (0x00000008)

public static final int USAGE_NOTIFICATION_COMMUNICATION_REQUEST

Added in API level 21

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

Constant Value: 7 (0x00000007)

public static final int USAGE_NOTIFICATION_EVENT

Added in API level 21

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

Constant Value: 10 (0x0000000a)

public static final int USAGE_NOTIFICATION_RINGTONE

Added in API level 21

Usage value to use when the usage is telephony ringtone.

Constant Value: 6 (0x00000006)

public static final int USAGE_UNKNOWN

Added in API level 21

Usage value to use when the usage is unknown.

Constant Value: 0 (0x00000000)

public static final int USAGE_VOICE_COMMUNICATION

Added in API level 21

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

Constant Value: 2 (0x00000002)

public static final int USAGE_VOICE_COMMUNICATION_SIGNALLING

Added in API level 21

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

Constant Value: 3 (0x00000003)

Fields

public static final Creator<AudioAttributes> CREATOR

Added in API level 21

Public Methods

public int describeContents ()

Added in API level 21

Describe the kinds of special objects contained in this Parcelable's marshalled representation.

Returns
  • a bitmask indicating the set of special object types marshalled by the Parcelable.

public boolean equals (Object o)

Added in API level 21

Compares this instance with the specified object and indicates if they are equal. In order to be equal, o must represent the same object as this instance using a class-specific comparison. The general contract is that this comparison should be reflexive, symmetric, and transitive. Also, no object reference other than null is equal to null.

The default implementation returns true only if this == o. See Writing a correct equals method if you intend implementing your own equals method.

The general contract for the equals and hashCode() methods is that if equals returns true for any two objects, then hashCode() must return the same value for these objects. This means that subclasses of Object usually override either both methods or neither of them.

Parameters
o the object to compare this instance with.
Returns
  • true if the specified object is equal to this Object; false otherwise.

public int getContentType ()

Added in API level 21

Return the content type.

Returns

public int getFlags ()

Added in API level 21

Return the flags.

Returns
  • a combined mask of all flags

public int getUsage ()

Added in API level 21

Return the usage.

Returns

public int hashCode ()

Added in API level 21

Returns an integer hash code for this object. By contract, any two objects for which equals(Object) returns true must return the same hash code value. This means that subclasses of Object usually override both methods or neither method.

Note that hash values must not change over time unless information used in equals comparisons also changes.

See Writing a correct hashCode method if you intend implementing your own hashCode method.

Returns
  • this object's hash code.

public String toString ()

Added in API level 21

Returns a string containing a concise, human-readable description of this object. Subclasses are encouraged to override this method and provide an implementation that takes into account the object's type and data. The default implementation is equivalent to the following expression:

   getClass().getName() + '@' + Integer.toHexString(hashCode())

See Writing a useful toString method if you intend implementing your own toString method.

Returns
  • a printable representation of this object.

public void writeToParcel (Parcel dest, int flags)

Added in API level 21

Flatten this object in to a Parcel.

Parameters
dest The Parcel in which the object should be written.
flags Additional flags about how the object should be written. May be 0 or PARCELABLE_WRITE_RETURN_VALUE.