I ‘m using mediarecorder to capture audio through MIC. I have set the max duration to 20 seconds. The recording stops automatically and does not stop at my break point inside setOnInfoListener.
**UPDATE: Changed my code according to suggestion but still doesnt stop at the breakpoint inside the listener.**
mRecorder.reset();
mRecorder.setOnInfoListener(new OnInfoListener() {
@Override
public void onInfo(MediaRecorder mr, int what, int extra) {
if (what == MediaRecorder.MEDIA_RECORDER_INFO_MAX_DURATION_REACHED) {
mRecorder.stop();
}
}
});
mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mRecorder.setAudioSamplingRate(8000);
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.RAW_AMR);
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
mRecorder.setOutputFile(fileName);
mRecorder.setMaxDuration(20000);
try {
mRecorder.prepare();
} catch(IOException exception) {
mRecorder.reset();
mRecorder.release();
mRecorder = null;
return;
}
mRecorder.start();
Can someone please tell me why does the code not hit my onInfo method inside the listener rather silently stops recording.
Thanks
When you set the output format, try using THREE_GPP instead of RAW_AMR.
According to the documentation for
setOutputFormat():