我正在用媒体录像机通过麦克风捕捉音频。我已将最大持续时间设置为20秒。录制将自动停止,并且不会在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();

有人能告诉我为什么代码没有在监听器中命中我的oninfo方法,而是静静地停止录制。
谢谢

最佳答案

设置输出格式时,请尝试使用三个GPP而不是原始AMR。

mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);

根据documentation对于setOutputFormat()
It is recommended to always use 3GP format when using the
H.263 video encoder and AMR audio encoder. Using an MPEG-4
container format may confuse some desktop players.

关于android - MediaRecorder实现setOnInfoListener -max duration,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7183573/

10-09 16:01