一、 问题描述
如下所示,调用recorder.stop()时抛出异常:
Caused by: java.lang.RuntimeException: stop failed.
at android.media.MediaRecorder.stop(Native Method)
二、 分析原因
start和stop间隔时间太短:
三、 解决方案
调用stop()之前将OnErrorListener、OnInfoListener和PreviewDisplay置空:
recorder.setOnErrorListener(null);
recorder.setOnInfoListener(null);
recorder.setPreviewDisplay(null);
try {
recorder.stop();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (RuntimeException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}