public final class AudioAttributes extends Object implements Parcelable
AudioAttributes
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_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_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.AudioAttributes
are used for example in one of the AudioTrack
constructors (see AudioTrack.AudioTrack(AudioAttributes, AudioFormat, int, int, int)
),
to configure a MediaPlayer
(see MediaPlayer.setAudioAttributes(AudioAttributes)
or a
Notification
(see Notification.audioAttributes
). An
AudioAttributes
instance is built through its builder,
AudioAttributes.Builder
.
Modifier and Type | Class and Description |
---|---|
static interface |
AudioAttributes.AttributeContentType |
static interface |
AudioAttributes.AttributeUsage |
static class |
AudioAttributes.Builder
Builder class for
AudioAttributes objects. |
Parcelable.ClassLoaderCreator<T>, Parcelable.Creator<T>
Modifier and Type | Field and Description |
---|---|
static int |
CONTENT_TYPE_MOVIE
Content type value to use when the content type is a soundtrack, typically accompanying
a movie or TV program.
|
static int |
CONTENT_TYPE_MUSIC
Content type value to use when the content type is music.
|
static 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.
|
static int |
CONTENT_TYPE_SPEECH
Content type value to use when the content type is speech.
|
static int |
CONTENT_TYPE_UNKNOWN
Content type value to use when the content type is unknown, or other than the ones defined.
|
static Parcelable.Creator<AudioAttributes> |
CREATOR |
static int |
FLAG_AUDIBILITY_ENFORCED
Flag defining a behavior where the audibility of the sound will be ensured by the system.
|
static int |
FLAG_BEACON |
static int |
FLAG_BYPASS_INTERRUPTION_POLICY |
static int |
FLAG_BYPASS_MUTE |
static int |
FLAG_HW_AV_SYNC
Flag requesting the use of an output stream supporting hardware A/V synchronization.
|
static int |
FLAG_HW_HOTWORD |
static int |
FLAG_LOW_LATENCY
Flag requesting a low latency path when creating an AudioTrack.
|
static int |
FLAG_SCO |
static int |
FLAG_SECURE |
static int |
FLATTEN_TAGS |
static int[] |
SDK_USAGES |
static int |
SUPPRESSIBLE_CALL |
static int |
SUPPRESSIBLE_NOTIFICATION |
static SparseIntArray |
SUPPRESSIBLE_USAGES |
static int |
USAGE_ALARM
Usage value to use when the usage is an alarm (e.g. wake-up alarm).
|
static int |
USAGE_ASSISTANCE_ACCESSIBILITY
Usage value to use when the usage is for accessibility, such as with
a screen reader.
|
static int |
USAGE_ASSISTANCE_NAVIGATION_GUIDANCE
Usage value to use when the usage is driving or navigation directions.
|
static int |
USAGE_ASSISTANCE_SONIFICATION
Usage value to use when the usage is sonification, such as with user
interface sounds.
|
static int |
USAGE_GAME
Usage value to use when the usage is for game audio.
|
static int |
USAGE_MEDIA
Usage value to use when the usage is media, such as music, or movie
soundtracks.
|
static int |
USAGE_NOTIFICATION
Usage value to use when the usage is notification.
|
static 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.
|
static int |
USAGE_NOTIFICATION_COMMUNICATION_INSTANT
Usage value to use when the usage is notification for an "instant"
communication such as a chat, or SMS.
|
static 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.
|
static 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.
|
static int |
USAGE_NOTIFICATION_RINGTONE
Usage value to use when the usage is telephony ringtone.
|
static int |
USAGE_UNKNOWN
Usage value to use when the usage is unknown.
|
static int |
USAGE_VIRTUAL_SOURCE |
static int |
USAGE_VOICE_COMMUNICATION
Usage value to use when the usage is voice communications, such as telephony
or VoIP.
|
static 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.
|
CONTENTS_FILE_DESCRIPTOR, PARCELABLE_ELIDE_DUPLICATES, PARCELABLE_WRITE_RETURN_VALUE
Modifier and Type | Method and Description |
---|---|
int |
describeContents()
Describe the kinds of special objects contained in this Parcelable
instance's marshaled representation.
|
boolean |
equals(Object o)
Indicates whether some other object is "equal to" this one.
|
int |
getAllFlags() |
Bundle |
getBundle() |
int |
getCapturePreset() |
int |
getContentType()
Return the content type.
|
int |
getFlags()
Return the flags.
|
Set<String> |
getTags() |
int |
getUsage()
Return the usage.
|
static int |
getVolumeControlStream(AudioAttributes aa) |
int |
hashCode()
Returns a hash code value for the object.
|
static int |
toLegacyStreamType(AudioAttributes aa) |
String |
toString()
Returns a string representation of the object.
|
static int |
usageForLegacyStreamType(int streamType) |
String |
usageToString() |
static String |
usageToString(int usage) |
void |
writeToParcel(Parcel dest,
int flags)
Flatten this object in to a Parcel.
|
public static final int CONTENT_TYPE_UNKNOWN
public static final int CONTENT_TYPE_SPEECH
public static final int CONTENT_TYPE_MUSIC
public static final int CONTENT_TYPE_MOVIE
public static final int CONTENT_TYPE_SONIFICATION
public static final int USAGE_UNKNOWN
public static final int USAGE_MEDIA
public static final int USAGE_VOICE_COMMUNICATION
public static final int USAGE_VOICE_COMMUNICATION_SIGNALLING
public static final int USAGE_ALARM
public static final int USAGE_NOTIFICATION
public static final int USAGE_NOTIFICATION_RINGTONE
public static final int USAGE_NOTIFICATION_COMMUNICATION_REQUEST
public static final int USAGE_NOTIFICATION_COMMUNICATION_INSTANT
public static final int USAGE_NOTIFICATION_COMMUNICATION_DELAYED
public static final int USAGE_NOTIFICATION_EVENT
public static final int USAGE_ASSISTANCE_ACCESSIBILITY
public static final int USAGE_ASSISTANCE_NAVIGATION_GUIDANCE
public static final int USAGE_ASSISTANCE_SONIFICATION
public static final int USAGE_GAME
public static final int USAGE_VIRTUAL_SOURCE
public static final int SUPPRESSIBLE_NOTIFICATION
SUPPRESSIBLE_USAGES
,
Constant Field Valuespublic static final int SUPPRESSIBLE_CALL
SUPPRESSIBLE_USAGES
,
Constant Field Valuespublic static final SparseIntArray SUPPRESSIBLE_USAGES
ZenModeHelper
public static final int[] SDK_USAGES
public static final int FLAG_AUDIBILITY_ENFORCED
public static final int FLAG_SECURE
public static final int FLAG_SCO
public static final int FLAG_BEACON
public static final int FLAG_HW_AV_SYNC
public static final int FLAG_HW_HOTWORD
public static final int FLAG_BYPASS_INTERRUPTION_POLICY
public static final int FLAG_BYPASS_MUTE
public static final int FLAG_LOW_LATENCY
AudioTrack.setBufferSizeInFrames(int)
. The buffer size can be optimized
by lowering it after each write() call until the audio glitches, which is detected by calling
AudioTrack.getUnderrunCount()
. Then the buffer size can be increased
until there are no glitches.
This tuning step should be done while playing silence.
This technique provides a compromise between latency and glitch rate.public static final int FLATTEN_TAGS
public static final Parcelable.Creator<AudioAttributes> CREATOR
public int getContentType()
AudioAttributes.Builder.setContentType(int)
public int getUsage()
AudioAttributes.Builder.setUsage(int)
public int getCapturePreset()
AudioAttributes.Builder.setCapturePreset(int)
or a
negative value if none has been set.public int getFlags()
public int getAllFlags()
public Bundle getBundle()
public int describeContents()
Parcelable
Parcelable.writeToParcel(Parcel, int)
,
the return value of this method must include the
Parcelable.CONTENTS_FILE_DESCRIPTOR
bit.describeContents
in interface Parcelable
Parcelable.CONTENTS_FILE_DESCRIPTOR
public void writeToParcel(Parcel dest, int flags)
Parcelable
writeToParcel
in interface Parcelable
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.PARCELABLE_WRITE_RETURN_VALUE
.public boolean equals(Object o)
Object
The equals
method implements an equivalence relation
on non-null object references:
x
, x.equals(x)
should return
true
.
x
and y
, x.equals(y)
should return true
if and only if
y.equals(x)
returns true
.
x
, y
, and z
, if
x.equals(y)
returns true
and
y.equals(z)
returns true
, then
x.equals(z)
should return true
.
x
and y
, multiple invocations of
x.equals(y)
consistently return true
or consistently return false
, provided no
information used in equals
comparisons on the
objects is modified.
x
,
x.equals(null)
should return false
.
The equals
method for class Object
implements
the most discriminating possible equivalence relation on objects;
that is, for any non-null reference values x
and
y
, this method returns true
if and only
if x
and y
refer to the same object
(x == y
has the value true
).
Note that it is generally necessary to override the hashCode
method whenever this method is overridden, so as to maintain the
general contract for the hashCode
method, which states
that equal objects must have equal hash codes.
equals
in class Object
o
- the reference object with which to compare.true
if this object is the same as the obj
argument; false
otherwise.Object.hashCode()
,
HashMap
public int hashCode()
Object
HashMap
.
The general contract of hashCode
is:
hashCode
method
must consistently return the same integer, provided no information
used in equals
comparisons on the object is modified.
This integer need not remain consistent from one execution of an
application to another execution of the same application.
equals(Object)
method, then calling the hashCode
method on each of
the two objects must produce the same integer result.
Object.equals(java.lang.Object)
method, then calling the hashCode
method on each of the
two objects must produce distinct integer results. However, the
programmer should be aware that producing distinct integer results
for unequal objects may improve the performance of hash tables.
As much as is reasonably practical, the hashCode method defined by
class Object
does return distinct integers for distinct
objects. (This is typically implemented by converting the internal
address of the object into an integer, but this implementation
technique is not required by the
JavaTM programming language.)
hashCode
in class Object
Object.equals(java.lang.Object)
,
System.identityHashCode(java.lang.Object)
public String toString()
Object
toString
method returns a string that
"textually represents" this object. The result should
be a concise but informative representation that is easy for a
person to read.
It is recommended that all subclasses override this method.
The toString
method for class Object
returns a string consisting of the name of the class of which the
object is an instance, the at-sign character `@
', and
the unsigned hexadecimal representation of the hash code of the
object. In other words, this method returns a string equal to the
value of:
getClass().getName() + '@' + Integer.toHexString(hashCode())
public String usageToString()
public static String usageToString(int usage)
public static int usageForLegacyStreamType(int streamType)
public static int getVolumeControlStream(AudioAttributes aa)
aa
- non-null AudioAttributes.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)
.public static int toLegacyStreamType(AudioAttributes aa)
aa
- non-null AudioAttributes.