public static class AudioAttributes.Builder extends Object
AudioAttributes
objects.
Here is an example where Builder
is used to define the
AudioAttributes
to be used by a new AudioTrack
instance:
AudioTrack myTrack = new AudioTrack( new AudioAttributes.Builder() .setUsage(AudioAttributes.USAGE_MEDIA) .setContentType(AudioAttributes.CONTENT_TYPE_MUSIC) .build(), myFormat, myBuffSize, AudioTrack.MODE_STREAM, mySession);
By default all types of information (usage, content type, flags) conveyed by an
AudioAttributes
instance are set to "unknown". Unknown information will be
interpreted as a default value that is dependent on the context of use, for instance a
MediaPlayer
will use a default usage of AudioAttributes.USAGE_MEDIA
.
Constructor and Description |
---|
Builder()
Constructs a new Builder with the defaults.
|
Builder(AudioAttributes aa)
Constructs a new Builder from a given AudioAttributes
|
Modifier and Type | Method and Description |
---|---|
AudioAttributes.Builder |
addBundle(Bundle bundle) |
AudioAttributes.Builder |
addTag(String tag) |
AudioAttributes |
build()
Combines all of the attributes that have been set and return a new
AudioAttributes object. |
AudioAttributes.Builder |
setCapturePreset(int preset) |
AudioAttributes.Builder |
setContentType(int contentType)
Sets the attribute describing the content type of the audio signal, such as speech,
or music.
|
AudioAttributes.Builder |
setFlags(int flags)
Sets the combination of flags.
|
AudioAttributes.Builder |
setInternalCapturePreset(int preset) |
AudioAttributes.Builder |
setInternalLegacyStreamType(int streamType) |
AudioAttributes.Builder |
setLegacyStreamType(int streamType)
Sets attributes as inferred from the legacy stream types.
|
AudioAttributes.Builder |
setUsage(int usage)
Sets the attribute describing what is the intended use of the the audio signal,
such as alarm or ringtone.
|
public Builder()
AudioAttributes.USAGE_UNKNOWN
and AudioAttributes.CONTENT_TYPE_UNKNOWN
, and flags are 0. It is recommended to
configure the usage (with setUsage(int)
) or deriving attributes from a legacy
stream type (with setLegacyStreamType(int)
) before calling build()
to override any default playback behavior in terms of routing and volume management.public Builder(AudioAttributes aa)
aa
- the AudioAttributes object whose data will be reused in the new Builder.public AudioAttributes build()
AudioAttributes
object.AudioAttributes
objectpublic AudioAttributes.Builder setUsage(int usage)
usage
- one of AudioAttributes.USAGE_UNKNOWN
,
AudioAttributes.USAGE_MEDIA
,
AudioAttributes.USAGE_VOICE_COMMUNICATION
,
AudioAttributes.USAGE_VOICE_COMMUNICATION_SIGNALLING
,
AudioAttributes.USAGE_ALARM
, AudioAttributes.USAGE_NOTIFICATION
,
AudioAttributes.USAGE_NOTIFICATION_RINGTONE
,
AudioAttributes.USAGE_NOTIFICATION_COMMUNICATION_REQUEST
,
AudioAttributes.USAGE_NOTIFICATION_COMMUNICATION_INSTANT
,
AudioAttributes.USAGE_NOTIFICATION_COMMUNICATION_DELAYED
,
AudioAttributes.USAGE_NOTIFICATION_EVENT
,
AudioAttributes.USAGE_ASSISTANCE_ACCESSIBILITY
,
AudioAttributes.USAGE_ASSISTANCE_NAVIGATION_GUIDANCE
,
AudioAttributes.USAGE_ASSISTANCE_SONIFICATION
,
AudioAttributes.USAGE_GAME
.public AudioAttributes.Builder setContentType(int contentType)
contentType
- the content type values, one of
AudioAttributes.CONTENT_TYPE_MOVIE
,
AudioAttributes.CONTENT_TYPE_MUSIC
,
AudioAttributes.CONTENT_TYPE_SONIFICATION
,
AudioAttributes.CONTENT_TYPE_SPEECH
,
AudioAttributes.CONTENT_TYPE_UNKNOWN
.public AudioAttributes.Builder setFlags(int flags)
flags
- a combination of AudioAttributes.FLAG_AUDIBILITY_ENFORCED
,
AudioAttributes.FLAG_HW_AV_SYNC
.public AudioAttributes.Builder addBundle(Bundle bundle)
bundle
- a non-null Bundlepublic AudioAttributes.Builder addTag(String tag)
tag
- public AudioAttributes.Builder setLegacyStreamType(int streamType)
AudioAttributes
instance to initialize some of
the attributes by information derived from a legacy stream type.streamType
- one of AudioManager.STREAM_VOICE_CALL
,
AudioManager.STREAM_SYSTEM
, AudioManager.STREAM_RING
,
AudioManager.STREAM_MUSIC
, AudioManager.STREAM_ALARM
,
or AudioManager.STREAM_NOTIFICATION
.public AudioAttributes.Builder setInternalLegacyStreamType(int streamType)
streamType
- public AudioAttributes.Builder setCapturePreset(int preset)
preset
- one of MediaRecorder.AudioSource.DEFAULT
,
MediaRecorder.AudioSource.MIC
, MediaRecorder.AudioSource.CAMCORDER
,
MediaRecorder.AudioSource.VOICE_RECOGNITION
,
MediaRecorder.AudioSource.VOICE_COMMUNICATION
or
MediaRecorder.AudioSource.UNPROCESSED
public AudioAttributes.Builder setInternalCapturePreset(int preset)
preset
-