AudioAttributes.Builder
public
static
class
AudioAttributes.Builder
extends Object
| java.lang.Object | |
| ↳ | android.media.AudioAttributes.Builder |
Builder class for 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.
Summary
Public constructors | |
|---|---|
AudioAttributes.Builder()
Constructs a new Builder with the defaults. |
|
AudioAttributes.Builder(AudioAttributes aa)
Constructs a new Builder from a given AudioAttributes |
|
Public methods | |
|---|---|
AudioAttributes
|
build()
Combines all of the attributes that have been set and return a new
|
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
|
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. |
Inherited methods | |
|---|---|
Public constructors
AudioAttributes.Builder
public AudioAttributes.Builder ()
Constructs a new Builder with the defaults.
By default, usage and content type are respectively 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.
AudioAttributes.Builder
public AudioAttributes.Builder (AudioAttributes aa)
Constructs a new Builder from a given AudioAttributes
| Parameters | |
|---|---|
aa |
AudioAttributes: the AudioAttributes object whose data will be reused in the new Builder. |
Public methods
build
public AudioAttributes build ()
Combines all of the attributes that have been set and return a new
AudioAttributes object.
| Returns | |
|---|---|
AudioAttributes |
a new AudioAttributes object |
setContentType
public AudioAttributes.Builder setContentType (int contentType)
Sets the attribute describing the content type of the audio signal, such as speech, or music.
| Parameters | |
|---|---|
contentType |
int: 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.
Value is AudioAttributes.CONTENT_TYPE_UNKNOWN, AudioAttributes.CONTENT_TYPE_SPEECH, AudioAttributes.CONTENT_TYPE_MUSIC, AudioAttributes.CONTENT_TYPE_MOVIE, or AudioAttributes.CONTENT_TYPE_SONIFICATION |
| Returns | |
|---|---|
AudioAttributes.Builder |
the same Builder instance. |
setFlags
public AudioAttributes.Builder setFlags (int flags)
Sets the combination of flags. This is a bitwise OR with the existing flags.
| Parameters | |
|---|---|
flags |
int: a combination of AudioAttributes#FLAG_AUDIBILITY_ENFORCED,
AudioAttributes#FLAG_HW_AV_SYNC. |
| Returns | |
|---|---|
AudioAttributes.Builder |
the same Builder instance. |
setLegacyStreamType
public AudioAttributes.Builder setLegacyStreamType (int streamType)
Sets attributes as inferred from the legacy stream types.
Use this method when building an AudioAttributes instance to initialize some of
the attributes by information derived from a legacy stream type.
| Parameters | |
|---|---|
streamType |
int: one of AudioManager#STREAM_VOICE_CALL,
AudioManager#STREAM_SYSTEM, AudioManager#STREAM_RING,
AudioManager#STREAM_MUSIC, AudioManager#STREAM_ALARM,
or AudioManager#STREAM_NOTIFICATION. |
| Returns | |
|---|---|
AudioAttributes.Builder |
the same Builder instance. |
setUsage
public AudioAttributes.Builder setUsage (int usage)
Sets the attribute describing what is the intended use of the the audio signal, such as alarm or ringtone.
| Returns | |
|---|---|
AudioAttributes.Builder |
the same Builder instance. |