Android使用MediaRecorder的stop方法报"stop failed"错误的解决方案

一、 问题描述

如下所示,调用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();
}

四、 参考文献

发布了91 篇原创文章 · 获赞 39 · 访问量 18万+

猜你喜欢

转载自blog.csdn.net/zy13608089849/article/details/81225882
今日推荐