AudioAttributesCompat
class AudioAttributesCompat : VersionedParcelable
A class to encapsulate a collection of attributes describing information about an audio stream.
AudioAttributesCompat 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_MEDIAandUSAGE_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 inAudioAttributesCompatand it is recommended to build any instance with this information supplied, seeAudioAttributesCompat.Builderfor 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_MOVIEfor a movie streaming service orCONTENT_TYPE_MUSICfor 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, AudioAttributesCompat.Builder. Also see android.media.AudioAttributes for the framework implementation of this class.
Summary
Nested types |
|---|
|
Builder class for |
Constants |
|
|---|---|
const Int |
Content type value to use when the content type is a soundtrack, typically accompanying a movie or TV program. |
const Int |
Content type value to use when the content type is music. |
const 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. |
const Int |
Content type value to use when the content type is speech. |
const Int |
Content type value to use when the content type is unknown, or other than the ones defined. |
const Int |
Flag defining a behavior where the audibility of the sound will be ensured by the system. |
const Int |
FLAG_HW_AV_SYNC = 16Flag requesting the use of an output stream supporting hardware A/V synchronization. |
const Int |
USAGE_ALARM = 4Usage value to use when the usage is an alarm (e.g. wake-up alarm). |
const Int |
Usage value to use when the usage is for accessibility, such as with a screen reader. |
const Int |
Usage value to use when the usage is driving or navigation directions. |
const Int |
Usage value to use when the usage is sonification, such as with user interface sounds. |
const Int |
USAGE_ASSISTANT = 16Usage value to use for audio responses to user queries, audio instructions or help utterances. |
const Int |
USAGE_GAME = 14Usage value to use when the usage is for game audio. |
const Int |
USAGE_MEDIA = 1Usage value to use when the usage is media, such as music, or movie soundtracks. |
const Int |
Usage value to use when the usage is notification. |
const Int |
Usage value to use when the usage is notification for a non-immediate type of communication such as e-mail. |
const Int |
Usage value to use when the usage is notification for an "instant" communication such as a chat, or SMS. |
const Int |
Usage value to use when the usage is a request to enter/end a communication, such as a VoIP communication or video-conference. |
const Int |
Usage value to use when the usage is to attract the user's attention, such as a reminder or low battery warning. |
const Int |
Usage value to use when the usage is telephony ringtone. |
const Int |
USAGE_UNKNOWN = 0Usage value to use when the usage is unknown. |
const Int |
Usage value to use when the usage is voice communications, such as telephony or VoIP. |
const Int |
Usage value to use when the usage is in-call signalling, such as with a "busy" beep, or DTMF tones. |
Public functions |
|
|---|---|
Boolean |
|
Int |
Returns the content type. |
Int |
getFlags()Returns the flags. |
Int |
Returns a stream type passed to |
Int |
getUsage()Returns the usage. |
Int |
Returns the stream type matching the given attributes for volume control. |
Int |
hashCode() |
String! |
toString() |
Any? |
unwrap()If the current SDK level is 21 or higher, return the |
java-static AudioAttributesCompat? |
Creates an |
Constants
CONTENT_TYPE_MOVIE
const val CONTENT_TYPE_MOVIE = 3: Int
Content type value to use when the content type is a soundtrack, typically accompanying a movie or TV program.
CONTENT_TYPE_MUSIC
const val CONTENT_TYPE_MUSIC = 2: Int
Content type value to use when the content type is music.
CONTENT_TYPE_SONIFICATION
const val CONTENT_TYPE_SONIFICATION = 4: 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.
CONTENT_TYPE_SPEECH
const val CONTENT_TYPE_SPEECH = 1: Int
Content type value to use when the content type is speech.
CONTENT_TYPE_UNKNOWN
const val CONTENT_TYPE_UNKNOWN = 0: Int
Content type value to use when the content type is unknown, or other than the ones defined.
FLAG_AUDIBILITY_ENFORCED
const val FLAG_AUDIBILITY_ENFORCED = 1: Int
Flag defining a behavior where the audibility of the sound will be ensured by the system.
FLAG_HW_AV_SYNC
const val FLAG_HW_AV_SYNC = 16: Int
Flag requesting the use of an output stream supporting hardware A/V synchronization.
USAGE_ALARM
const val USAGE_ALARM = 4: Int
Usage value to use when the usage is an alarm (e.g. wake-up alarm).
USAGE_ASSISTANCE_ACCESSIBILITY
const val USAGE_ASSISTANCE_ACCESSIBILITY = 11: Int
Usage value to use when the usage is for accessibility, such as with a screen reader.
USAGE_ASSISTANCE_NAVIGATION_GUIDANCE
const val USAGE_ASSISTANCE_NAVIGATION_GUIDANCE = 12: Int
Usage value to use when the usage is driving or navigation directions.
USAGE_ASSISTANCE_SONIFICATION
const val USAGE_ASSISTANCE_SONIFICATION = 13: Int
Usage value to use when the usage is sonification, such as with user interface sounds.
USAGE_ASSISTANT
const val USAGE_ASSISTANT = 16: Int
Usage value to use for audio responses to user queries, audio instructions or help utterances.
USAGE_GAME
const val USAGE_GAME = 14: Int
Usage value to use when the usage is for game audio.
USAGE_MEDIA
const val USAGE_MEDIA = 1: Int
Usage value to use when the usage is media, such as music, or movie soundtracks.
USAGE_NOTIFICATION
const val USAGE_NOTIFICATION = 5: Int
Usage value to use when the usage is notification. See other notification usages for more specialized uses.
USAGE_NOTIFICATION_COMMUNICATION_DELAYED
const val USAGE_NOTIFICATION_COMMUNICATION_DELAYED = 9: Int
Usage value to use when the usage is notification for a non-immediate type of communication such as e-mail.
USAGE_NOTIFICATION_COMMUNICATION_INSTANT
const val USAGE_NOTIFICATION_COMMUNICATION_INSTANT = 8: Int
Usage value to use when the usage is notification for an "instant" communication such as a chat, or SMS.
USAGE_NOTIFICATION_COMMUNICATION_REQUEST
const val USAGE_NOTIFICATION_COMMUNICATION_REQUEST = 7: Int
Usage value to use when the usage is a request to enter/end a communication, such as a VoIP communication or video-conference.
USAGE_NOTIFICATION_EVENT
const val USAGE_NOTIFICATION_EVENT = 10: Int
Usage value to use when the usage is to attract the user's attention, such as a reminder or low battery warning.
USAGE_NOTIFICATION_RINGTONE
const val USAGE_NOTIFICATION_RINGTONE = 6: Int
Usage value to use when the usage is telephony ringtone.
USAGE_UNKNOWN
const val USAGE_UNKNOWN = 0: Int
Usage value to use when the usage is unknown.
USAGE_VOICE_COMMUNICATION
const val USAGE_VOICE_COMMUNICATION = 2: Int
Usage value to use when the usage is voice communications, such as telephony or VoIP.
USAGE_VOICE_COMMUNICATION_SIGNALLING
const val USAGE_VOICE_COMMUNICATION_SIGNALLING = 3: Int
Usage value to use when the usage is in-call signalling, such as with a "busy" beep, or DTMF tones.
Public functions
getContentType
fun getContentType(): Int
Returns the content type.
| Returns | |
|---|---|
Int |
one of the values that can be set in |
getFlags
fun getFlags(): Int
Returns the flags.
| Returns | |
|---|---|
Int |
a combined mask of all flags |
getLegacyStreamType
fun getLegacyStreamType(): Int
Returns a stream type passed to setLegacyStreamType, or best guessing from flags and usage, or -1 if there is no converting logic in framework side (API 21+).
| Returns | |
|---|---|
Int |
the stream type {@see AudioManager} |
getVolumeControlStream
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 android.app.Activity with setVolumeControlStream. Do not use this method to set the stream type on an audio player object (e.g. android.media.AudioTrack, android.media.MediaPlayer) as this is deprecated; use AudioAttributes instead.
| Returns | |
|---|---|
Int |
a valid stream type for |
unwrap
fun unwrap(): Any?
If the current SDK level is 21 or higher, return the AudioAttributes object inside this AudioAttributesCompat. Otherwise null.
| Returns | |
|---|---|
Any? |
the underlying |
wrap
java-static fun wrap(aa: Any): AudioAttributesCompat?
Creates an AudioAttributesCompat given an API 21 AudioAttributes object.
| Parameters | |
|---|---|
aa: Any |
an instance of |
| Returns | |
|---|---|
AudioAttributesCompat? |
the new |