public class MediaRecorder extends Object
Modifier and Type | Field and Description |
---|---|
static int |
RECORDSTATE_RECORDING
The state indicating that the recorder is recording
|
static int |
RECORDSTATE_STOPPED
The state indicating that the recorder is not recording
|
Constructor and Description |
---|
MediaRecorder()
Creates an MediaRecorder.
Call release() to release native resources after using the
MediaRecorder. |
Modifier and Type | Method and Description |
---|---|
int |
getRecordingState()
Returns the recording state.
|
void |
prepare()
Prepares the recorder to begin capturing and encoding data,
synchronously.
|
void |
release()
Releases the native MediaRecorder resources.
|
void |
reset()
Set the MediaRecorder to its idle state.
|
void |
setAudioBitRate(int audioBitRate)
Set bit rate.
|
void |
setAudioSampleRate(int sampleRateInHz)
Set audio sample rate in Hertz.
|
void |
setChannelConfig(int channelConfig)
Set the configuration of the audio channels.
|
void |
setOutputFile(String outputFilePath)
Sets the path of the output file to be produced.
|
void |
setOutputFormat(int outFormat)
Sets the format of the output file produced during recording.
|
void |
start()
Begins capturing and encoding data to the file specified with
setOutputFile().
|
void |
stop()
Stops recording.
|
public static final int RECORDSTATE_STOPPED
public static final int RECORDSTATE_RECORDING
public MediaRecorder() throws IOException
release()
to release native resources after using the
MediaRecorder.IOException
- if failed to create recorderpublic void setAudioSampleRate(int sampleRateInHz) throws IllegalArgumentException
sampleRateInHz
- sample rate. Normally use 8000
,
16000
, 22050
, 44100
,
48000
. Default is 16000
.IllegalArgumentException
public void setChannelConfig(int channelConfig) throws IllegalArgumentException
channelConfig
- audio channel configuration. See
AudioFormat.CHANNEL_MONO
and
AudioFormat.CHANNEL_STEREO
. Default is
CHANNEL_MONO
IllegalArgumentException
public void setAudioBitRate(int audioBitRate) throws IllegalArgumentException
audioBitRate
- bit per sample. Normally use 8
,
16
. Default is 16
IllegalArgumentException
public void setOutputFile(String outputFilePath) throws IOException
Environment.getRootDirectory()
or
Environment.getExternalStorageDirectory()
. outputFilePath
- the pathname to use.IOException
public void setOutputFormat(int outFormat) throws IllegalArgumentException
outFormat
- the output format to use. See
MediaFormat.FORMAT_WAV
,
MediaFormat.FORMAT_AMR_NB
and
MediaFormat.FORMAT_AMR_WB
IllegalArgumentException
public int getRecordingState()
RECORDSTATE_STOPPED
,
RECORDSTATE_RECORDING
public void prepare() throws IOException
IOException
- if prepare failspublic void start() throws IOException
IOException
- if start failspublic void stop() throws IOException
IOException
public void reset() throws IOException
IOException
public void release() throws IOException
IOException