# Print output for @column tags ?>
public
static
class
AudioRecord.Builder
extends Object
| java.lang.Object | |
| ↳ | android.media.AudioRecord.Builder |
Builder class for AudioRecord objects.
Use this class to configure and create an AudioRecord instance. By setting the
recording source and audio format parameters, you indicate which of
those vary from the default behavior on the device.
Here is an example where Builder is used to specify all AudioFormat
parameters, to be used by a new AudioRecord instance:
AudioRecord recorder = new AudioRecord.Builder()
.setAudioSource(MediaRecorder.AudioSource.VOICE_COMMUNICATION)
.setAudioFormat(new AudioFormat.Builder()
.setEncoding(AudioFormat.ENCODING_PCM_16BIT)
.setSampleRate(32000)
.setChannelMask(AudioFormat.CHANNEL_IN_MONO)
.build())
.setBufferSizeInBytes(2*minBuffSize)
.build();
If the audio source is not set with setAudioSource(int),
MediaRecorder.AudioSource#DEFAULT is used.
If the audio format is not specified or is incomplete, its channel configuration will be
AudioFormat#CHANNEL_IN_MONO, and the encoding will be
AudioFormat#ENCODING_PCM_16BIT.
The sample rate will depend on the device actually selected for capture and can be queried
with AudioRecord.getSampleRate() method.
If the buffer size is not specified with setBufferSizeInBytes(int),
the minimum buffer size for the source is used.
Public constructors | |
|---|---|
Builder()
Constructs a new Builder with the default values as described above. |
|
Public methods | |
|---|---|
AudioRecord
|
build()
|
AudioRecord.Builder
|
setAudioFormat(AudioFormat format)
Sets the format of the audio data to be captured. |
AudioRecord.Builder
|
setAudioPlaybackCaptureConfig(AudioPlaybackCaptureConfiguration config)
Sets the |
AudioRecord.Builder
|
setAudioSource(int source)
|
AudioRecord.Builder
|
setBufferSizeInBytes(int bufferSizeInBytes)
Sets the total size (in bytes) of the buffer where audio data is written during the recording. |
AudioRecord.Builder
|
setContext(Context context)
Sets the context the record belongs to. |
AudioRecord.Builder
|
setPrivacySensitive(boolean privacySensitive)
Indicates that this capture request is privacy sensitive and that any concurrent capture is not permitted. |
Inherited methods | |
|---|---|
public Builder ()
Constructs a new Builder with the default values as described above.
public AudioRecord build ()
Requires Manifest.permission.RECORD_AUDIO
| Returns | |
|---|---|
AudioRecord |
a new AudioRecord instance successfully initialized with all
the parameters set on this Builder. |
| Throws | |
|---|---|
UnsupportedOperationException |
if the parameters set on the Builder
were incompatible, or if they are not supported by the device,
or if the device was not available. |
public AudioRecord.Builder setAudioFormat (AudioFormat format)
Sets the format of the audio data to be captured.
| Parameters | |
|---|---|
format |
AudioFormat: a non-null AudioFormat instance
This value cannot be null. |
| Returns | |
|---|---|
AudioRecord.Builder |
the same Builder instance. |
| Throws | |
|---|---|
|
java.lang.IllegalArgumentException |
IllegalArgumentException |
|
public AudioRecord.Builder setAudioPlaybackCaptureConfig (AudioPlaybackCaptureConfiguration config)
Sets the AudioRecord to record audio played by other apps.
| Parameters | |
|---|---|
config |
AudioPlaybackCaptureConfiguration: Defines what apps to record audio from (i.e., via either their uid or
the type of audio).
This value cannot be null. |
| Returns | |
|---|---|
AudioRecord.Builder |
|
| Throws | |
|---|---|
IllegalStateException |
if called in conjunction with setAudioSource(int). |
NullPointerException |
if config is null. |
public AudioRecord.Builder setAudioSource (int source)
| Parameters | |
|---|---|
source |
int: the audio source.
See MediaRecorder.AudioSource for the supported audio source definitions.
Value is MediaRecorder.AudioSource.DEFAULT, MediaRecorder.AudioSource.MIC, MediaRecorder.AudioSource.VOICE_UPLINK, MediaRecorder.AudioSource.VOICE_DOWNLINK, MediaRecorder.AudioSource.VOICE_CALL, MediaRecorder.AudioSource.CAMCORDER, MediaRecorder.AudioSource.VOICE_RECOGNITION, MediaRecorder.AudioSource.VOICE_COMMUNICATION, MediaRecorder.AudioSource.UNPROCESSED, or MediaRecorder.AudioSource.VOICE_PERFORMANCE |
| Returns | |
|---|---|
AudioRecord.Builder |
the same Builder instance. |
| Throws | |
|---|---|
|
java.lang.IllegalArgumentException |
IllegalArgumentException |
|
public AudioRecord.Builder setBufferSizeInBytes (int bufferSizeInBytes)
Sets the total size (in bytes) of the buffer where audio data is written
during the recording. New audio data can be read from this buffer in smaller chunks
than this size. See AudioRecord.getMinBufferSize(int, int, int) to determine the minimum
required buffer size for the successful creation of an AudioRecord instance.
Since bufferSizeInBytes may be internally increased to accommodate the source
requirements, use AudioRecord.getBufferSizeInFrames() to determine the actual buffer size
in frames.
| Parameters | |
|---|---|
bufferSizeInBytes |
int: a value strictly greater than 0 |
| Returns | |
|---|---|
AudioRecord.Builder |
the same Builder instance. |
| Throws | |
|---|---|
|
java.lang.IllegalArgumentException |
IllegalArgumentException |
|
public AudioRecord.Builder setContext (Context context)
Sets the context the record belongs to. This context will be used to pull information,
such as AttributionSource, which will be associated with
the AudioRecord. However, the context itself will not be retained by the AudioRecord.
| Parameters | |
|---|---|
context |
Context: a non-null Context instance
This value cannot be null. |
| Returns | |
|---|---|
AudioRecord.Builder |
the same Builder instance. |
public AudioRecord.Builder setPrivacySensitive (boolean privacySensitive)
Indicates that this capture request is privacy sensitive and that any concurrent capture is not permitted.
The default is not privacy sensitive except when the audio source set with
setAudioSource(int) is MediaRecorder.AudioSource#VOICE_COMMUNICATION or
MediaRecorder.AudioSource#CAMCORDER.
Always takes precedence over default from audio source when set explicitly.
Using this API is only permitted when the audio source is one of:
MediaRecorder.AudioSource#MICMediaRecorder.AudioSource#CAMCORDERMediaRecorder.AudioSource#VOICE_RECOGNITIONMediaRecorder.AudioSource#VOICE_COMMUNICATIONMediaRecorder.AudioSource#UNPROCESSEDMediaRecorder.AudioSource#VOICE_PERFORMANCEbuild() will throw an UnsupportedOperationException if this
condition is not met.
| Parameters | |
|---|---|
privacySensitive |
boolean: True if capture from this AudioRecord must be marked as privacy
sensitive, false otherwise. |
| Returns | |
|---|---|
AudioRecord.Builder |
This value cannot be null. |