start 和 stop的时候可能会IllegalStateException 处理的话我们可以捕捉 这里记录一下
try {
mMediaRecorder.prepare();
mMediaRecorder.start();
recordSuccessAction();
} catch (IOException e) {
e.printStackTrace();
} catch (IllegalStateException e) {
e.printStackTrace();
LogUtils.e(e.getMessage());
mMediaRecorder = null;//先重置为null
prepareTakeVideoAndStart(filePath);//然后重新初始化即可,包括设置重新配置等等
}
...
if (mMediaRecorder != null) {
mMediaRecorder.setOnErrorListener(null);
mMediaRecorder.setOnInfoListener(null);
mMediaRecorder.setPreviewDisplay(null);
try {
mMediaRecorder.stop();
} catch (IllegalStateException e) {
e.printStackTrace();
exception = true;
mMediaRecorder = null;//重置为null
mMediaRecorder = new MediaRecorder();//重新new对象
}
// mMediaRecorder.reset();
mMediaRecorder.release();
mMediaRecorder = null;
...
}
一般录制时间过短容易出现这种情况,可以考虑做做防抖动