AudioAttributes
public
final
class
AudioAttributes
extends Object
implements
Parcelable
| java.lang.Object | |
| ↳ | android.media.AudioAttributes |
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_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 inAudioAttributesand it is recommended to build any instance with this information supplied, seeAudioAttributes.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.
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 |
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 |
FLAG_LOW_LATENCY
This constant was deprecated
in API level O.
Use |
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_ASSISTANT
Usage value to use for audio responses to user queries, audio instructions or help utterances. |
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. |
Inherited constants |
|---|
android.os.Parcelable
|
Fields | |
|---|---|
public
static
final
Creator<AudioAttributes> |
CREATOR
|
Public methods | |
|---|---|
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
|
getContentType()
Return the content type. |
int
|
getFlags()
Return the flags. |
int
|
getUsage()
Return the usage. |
int
|
getVolumeControlStream()
Returns the stream type matching this |
int
|
hashCode()
Returns a hash code value for the object. |
String
|
toString()
Returns a string representation of the object. |
void
|
writeToParcel(Parcel dest, int flags)
Flatten this object in to a Parcel. |
Inherited methods | |
|---|---|
java.lang.Object
| |
android.os.Parcelable
| |
Constants
CONTENT_TYPE_MOVIE
int CONTENT_TYPE_MOVIE
Content type value to use when the content type is a soundtrack, typically accompanying a movie or TV program.
Constant Value: 3 (0x00000003)
CONTENT_TYPE_MUSIC
int CONTENT_TYPE_MUSIC
Content type value to use when the content type is music.
Constant Value: 2 (0x00000002)
CONTENT_TYPE_SONIFICATION
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. These sounds are mostly synthesized or short Foley sounds.
Constant Value: 4 (0x00000004)
CONTENT_TYPE_SPEECH
int CONTENT_TYPE_SPEECH
Content type value to use when the content type is speech.
Constant Value: 1 (0x00000001)
CONTENT_TYPE_UNKNOWN
int CONTENT_TYPE_UNKNOWN
Content type value to use when the content type is unknown, or other than the ones defined.
Constant Value: 0 (0x00000000)
FLAG_AUDIBILITY_ENFORCED
int FLAG_AUDIBILITY_ENFORCED
Flag defining a behavior where the audibility of the sound will be ensured by the system.
Constant Value: 1 (0x00000001)
FLAG_HW_AV_SYNC
int FLAG_HW_AV_SYNC
Flag requesting the use of an output stream supporting hardware A/V synchronization.
Constant Value: 16 (0x00000010)
FLAG_LOW_LATENCY
int FLAG_LOW_LATENCY
This constant was deprecated
in API level O.
Use setPerformanceMode(int) with
PERFORMANCE_MODE_LOW_LATENCY to control performance.
Flag requesting a low latency path when creating an AudioTrack.
When using this flag, the sample rate must match the native sample rate
of the device. Effects processing is also unavailable.
Note that if this flag is used without specifying a bufferSizeInBytes then the
AudioTrack's actual buffer size may be too small. It is recommended that a fairly
large buffer should be specified when the AudioTrack is created.
Then the actual size can be reduced by calling
setBufferSizeInFrames(int). The buffer size can be optimized
by lowering it after each write() call until the audio glitches, which is detected by calling
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.
Constant Value: 256 (0x00000100)
USAGE_ALARM
int USAGE_ALARM
Usage value to use when the usage is an alarm (e.g. wake-up alarm).
Constant Value: 4 (0x00000004)
USAGE_ASSISTANCE_ACCESSIBILITY
int USAGE_ASSISTANCE_ACCESSIBILITY
Usage value to use when the usage is for accessibility, such as with a screen reader.
Constant Value: 11 (0x0000000b)
USAGE_ASSISTANCE_NAVIGATION_GUIDANCE
int USAGE_ASSISTANCE_NAVIGATION_GUIDANCE
Usage value to use when the usage is driving or navigation directions.
Constant Value: 12 (0x0000000c)
USAGE_ASSISTANCE_SONIFICATION
int USAGE_ASSISTANCE_SONIFICATION
Usage value to use when the usage is sonification, such as with user interface sounds.
Constant Value: 13 (0x0000000d)
USAGE_ASSISTANT
int USAGE_ASSISTANT
Usage value to use for audio responses to user queries, audio instructions or help utterances.
Constant Value: 16 (0x00000010)
USAGE_GAME
int USAGE_GAME
Usage value to use when the usage is for game audio.
Constant Value: 14 (0x0000000e)
USAGE_MEDIA
int USAGE_MEDIA
Usage value to use when the usage is media, such as music, or movie soundtracks.
Constant Value: 1 (0x00000001)
USAGE_NOTIFICATION
int USAGE_NOTIFICATION
Usage value to use when the usage is notification. See other notification usages for more specialized uses.
Constant Value: 5 (0x00000005)
USAGE_NOTIFICATION_COMMUNICATION_DELAYED
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.
Constant Value: 9 (0x00000009)
USAGE_NOTIFICATION_COMMUNICATION_INSTANT
int USAGE_NOTIFICATION_COMMUNICATION_INSTANT
Usage value to use when the usage is notification for an "instant" communication such as a chat, or SMS.
Constant Value: 8 (0x00000008)
USAGE_NOTIFICATION_COMMUNICATION_REQUEST
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.
Constant Value: 7 (0x00000007)
USAGE_NOTIFICATION_EVENT
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.
Constant Value: 10 (0x0000000a)
USAGE_NOTIFICATION_RINGTONE
int USAGE_NOTIFICATION_RINGTONE
Usage value to use when the usage is telephony ringtone.
Constant Value: 6 (0x00000006)
USAGE_UNKNOWN
int USAGE_UNKNOWN
Usage value to use when the usage is unknown.
Constant Value: 0 (0x00000000)
USAGE_VOICE_COMMUNICATION
int USAGE_VOICE_COMMUNICATION
Usage value to use when the usage is voice communications, such as telephony or VoIP.
Constant Value: 2 (0x00000002)
USAGE_VOICE_COMMUNICATION_SIGNALLING
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.
Constant Value: 3 (0x00000003)
Fields
Public methods
describeContents
int describeContents ()
Describe the kinds of special objects contained in this Parcelable
instance's marshaled representation. For example, if the object will
include a file descriptor in the output of writeToParcel(Parcel, int),
the return value of this method must include the
CONTENTS_FILE_DESCRIPTOR bit.
| Returns | |
|---|---|
int |
a bitmask indicating the set of special object types marshaled by this Parcelable object instance. |
equals
boolean equals (Object o)
Indicates whether some other object is "equal to" this one.
The equals method implements an equivalence relation
on non-null object references:
- It is reflexive: for any non-null reference value
x,x.equals(x)should returntrue. - It is symmetric: for any non-null reference values
xandy,x.equals(y)should returntrueif and only ify.equals(x)returnstrue. - It is transitive: for any non-null reference values
x,y, andz, ifx.equals(y)returnstrueandy.equals(z)returnstrue, thenx.equals(z)should returntrue. - It is consistent: for any non-null reference values
xandy, multiple invocations ofx.equals(y)consistently returntrueor consistently returnfalse, provided no information used inequalscomparisons on the objects is modified. - For any non-null reference value
x,x.equals(null)should returnfalse.
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.
| Parameters | |
|---|---|
o |
Object: the reference object with which to compare. |
| Returns | |
|---|---|
boolean |
true if this object is the same as the obj
argument; false otherwise. |
getContentType
int getContentType ()
Return the content type.
| Returns | |
|---|---|
int |
one of the values that can be set in setContentType(int)
|
getFlags
int getFlags ()
Return the flags.
| Returns | |
|---|---|
int |
a combined mask of all flags |
getUsage
int getUsage ()
Return the usage.
| Returns | |
|---|---|
int |
one of the values that can be set in setUsage(int)
|
getVolumeControlStream
int getVolumeControlStream ()
Returns the stream type matching this AudioAttributes instance for volume control.
Use this method to derive the stream type needed to configure the volume
control slider in an Activity with
setVolumeControlStream(int) for playback conducted with these
attributes.
Do not use this method to set the stream type on an audio player object
(e.g. AudioTrack, MediaPlayer) as this is deprecated,
use AudioAttributes instead.
| Returns | |
|---|---|
int |
a valid stream type for Activity or stream volume control that matches
the attributes, or USE_DEFAULT_STREAM_TYPE if there isn't a direct
match. Note that USE_DEFAULT_STREAM_TYPE is not a valid value
for setStreamVolume(int, int, int).
|
hashCode
int hashCode ()
Returns a hash code value for the object. This method is
supported for the benefit of hash tables such as those provided by
HashMap.
The general contract of hashCode is:
- Whenever it is invoked on the same object more than once during
an execution of a Java application, the
hashCodemethod must consistently return the same integer, provided no information used inequalscomparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application. - If two objects are equal according to the
equals(Object)method, then calling thehashCodemethod on each of the two objects must produce the same integer result. - It is not required that if two objects are unequal
according to the
equals(java.lang.Object)method, then calling thehashCodemethod 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
Java™ programming language.)
| Returns | |
|---|---|
int |
a hash code value for this object. |
toString
String toString ()
Returns a string representation of the object. In general, the
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())
| Returns | |
|---|---|
String |
a string representation of the object. |
writeToParcel
void writeToParcel (Parcel dest, int flags)
Flatten this object in to a Parcel.
| Parameters | |
|---|---|
dest |
Parcel: The Parcel in which the object should be written. |
flags |
int: Additional flags about how the object should be written.
May be 0 or PARCELABLE_WRITE_RETURN_VALUE.
|
Interfaces
- AudioManager.OnAudioFocusChangeListener
- AudioRecord.OnRecordPositionUpdateListener
- AudioRecord.OnRoutingChangedListener
- AudioRouting
- AudioRouting.OnRoutingChangedListener
- AudioTrack.OnPlaybackPositionUpdateListener
- AudioTrack.OnRoutingChangedListener
- ImageReader.OnImageAvailableListener
- ImageWriter.OnImageReleasedListener
- JetPlayer.OnJetEventListener
- MediaCas.EventListener
- MediaCodec.OnFrameRenderedListener
- MediaDrm.OnEventListener
- MediaDrm.OnExpirationUpdateListener
- MediaDrm.OnKeyStatusChangeListener
- MediaPlayer.OnBufferingUpdateListener
- MediaPlayer.OnCompletionListener
- MediaPlayer.OnDrmConfigHelper
- MediaPlayer.OnDrmInfoListener
- MediaPlayer.OnDrmPreparedListener
- MediaPlayer.OnErrorListener
- MediaPlayer.OnInfoListener
- MediaPlayer.OnPreparedListener
- MediaPlayer.OnSeekCompleteListener
- MediaPlayer.OnTimedMetaDataAvailableListener
- MediaPlayer.OnTimedTextListener
- MediaPlayer.OnVideoSizeChangedListener
- MediaRecorder.OnErrorListener
- MediaRecorder.OnInfoListener
- MediaScannerConnection.MediaScannerConnectionClient
- MediaScannerConnection.OnScanCompletedListener
- MediaSync.OnErrorListener
- RemoteControlClient.OnGetPlaybackPositionListener
- RemoteControlClient.OnMetadataUpdateListener
- RemoteControlClient.OnPlaybackPositionUpdateListener
- RemoteController.OnClientUpdateListener
- SoundPool.OnLoadCompleteListener
- VolumeAutomation
Classes
- AsyncPlayer
- AudioAttributes
- AudioAttributes.Builder
- AudioDeviceCallback
- AudioDeviceInfo
- AudioFocusRequest
- AudioFocusRequest.Builder
- AudioFormat
- AudioFormat.Builder
- AudioManager
- AudioManager.AudioPlaybackCallback
- AudioManager.AudioRecordingCallback
- AudioPlaybackConfiguration
- AudioRecord
- AudioRecord.Builder
- AudioRecordingConfiguration
- AudioTimestamp
- AudioTrack
- AudioTrack.Builder
- CamcorderProfile
- CameraProfile
- DrmInitData
- DrmInitData.SchemeInitData
- ExifInterface
- FaceDetector
- FaceDetector.Face
- Image
- Image.Plane
- ImageReader
- ImageWriter
- JetPlayer
- MediaActionSound
- MediaCas
- MediaCas.PluginDescriptor
- MediaCas.Session
- MediaCodec
- MediaCodec.BufferInfo
- MediaCodec.Callback
- MediaCodec.CryptoInfo
- MediaCodec.CryptoInfo.Pattern
- MediaCodec.MetricsConstants
- MediaCodecInfo
- MediaCodecInfo.AudioCapabilities
- MediaCodecInfo.CodecCapabilities
- MediaCodecInfo.CodecProfileLevel
- MediaCodecInfo.EncoderCapabilities
- MediaCodecInfo.VideoCapabilities
- MediaCodecList
- MediaCrypto
- MediaDataSource
- MediaDescrambler
- MediaDescription
- MediaDescription.Builder
- MediaDrm
- MediaDrm.CryptoSession
- MediaDrm.KeyRequest
- MediaDrm.KeyStatus
- MediaDrm.ProvisionRequest
- MediaExtractor
- MediaExtractor.CasInfo
- MediaExtractor.MetricsConstants
- MediaFormat
- MediaMetadata
- MediaMetadata.Builder
- MediaMetadataEditor
- MediaMetadataRetriever
- MediaMuxer
- MediaMuxer.OutputFormat
- MediaPlayer
- MediaPlayer.DrmInfo
- MediaPlayer.MetricsConstants
- MediaPlayer.TrackInfo
- MediaRecorder
- MediaRecorder.AudioEncoder
- MediaRecorder.AudioSource
- MediaRecorder.MetricsConstants
- MediaRecorder.OutputFormat
- MediaRecorder.VideoEncoder
- MediaRecorder.VideoSource
- MediaRouter
- MediaRouter.Callback
- MediaRouter.RouteCategory
- MediaRouter.RouteGroup
- MediaRouter.RouteInfo
- MediaRouter.SimpleCallback
- MediaRouter.UserRouteInfo
- MediaRouter.VolumeCallback
- MediaScannerConnection
- MediaSync
- MediaSync.Callback
- MediaSyncEvent
- MediaTimestamp
- PlaybackParams
- Rating
- RemoteControlClient
- RemoteControlClient.MetadataEditor
- RemoteController
- RemoteController.MetadataEditor
- Ringtone
- RingtoneManager
- SoundPool
- SoundPool.Builder
- SyncParams
- ThumbnailUtils
- TimedMetaData
- TimedText
- ToneGenerator
- VolumeProvider
- VolumeShaper
- VolumeShaper.Configuration
- VolumeShaper.Configuration.Builder
- VolumeShaper.Operation
Exceptions
- DeniedByServerException
- MediaCasException
- MediaCasException.DeniedByServerException
- MediaCasException.NotProvisionedException
- MediaCasException.ResourceBusyException
- MediaCasException.UnsupportedCasException
- MediaCasStateException
- MediaCodec.CodecException
- MediaCodec.CryptoException
- MediaCryptoException
- MediaDrm.MediaDrmStateException
- MediaDrmException
- MediaDrmResetException
- MediaPlayer.NoDrmSchemeException
- MediaPlayer.ProvisioningNetworkErrorException
- MediaPlayer.ProvisioningServerErrorException
- NotProvisionedException
- ResourceBusyException
- UnsupportedSchemeException