我的Android进阶之旅------>Android中MediaRecorder.stop()报错 java.lang.RuntimeException: stop failed.【转】
2017-10-26 13:42
696 查看
本文转载自:http://blog.csdn.net/ouyang_peng/article/details/48048975
今天在调用MediaRecorder.stop(),报错了,java.lang.RuntimeException: stop failed.
[html] view plain copy
E/AndroidRuntime(7698): Cause by: java.lang.RuntimeException: stop failed.
E/AndroidRuntime(7698): at android.media.MediaRecorder.stop(Native Method)
E/AndroidRuntime(7698): at com.tintele.sos.VideoRecordService.stopRecord(VideoRecordService.java:298)
报错代码如下:
[java] view plain copy
if (mediarecorder != null) {
mediarecorder.stop();
mediarecorder.release();
mediarecorder = null;
if (mCamera != null) {
mCamera.release();
mCamera = null;
}
}
stop()方法源代码如下:
[java] view plain copy
/**
* Stops recording. Call this after start(). Once recording is stopped,
* you will have to configure it again as if it has just been constructed.
* Note that a RuntimeException is intentionally thrown to the
* application, if no valid audio/video data has been received when stop()
* is called. This happens if stop() is called immediately after
* start(). The failure lets the application take action accordingly to
* clean up the output file (delete the output file, for instance), since
* the output file is not properly constructed when this happens.
*
* @throws IllegalStateException if it is called before start()
*/
public native void stop() throws IllegalStateException;
源代码中说了:Note that a RuntimeException is intentionally thrown to the application, if no valid audio/video data has been received when stop() is called. This happens if stop() is called immediately after start().The failure lets the application take action accordingly to clean up the output file (delete the output file, for instance), since the output file is not properly constructed when this happens.
现在,在mediarecorder.stop();这一句报错了,现在在mediarecorder.stop();这句之前加几句就不会报错了
mediarecorder.setOnErrorListener(null);
mediarecorder.setOnInfoListener(null);
mediarecorder.setPreviewDisplay(null);
改后代码如下:
[java] view plain copy
if (mediarecorder != null) {
//added by ouyang start
try {
//下面三个参数必须加,不加的话会奔溃,在mediarecorder.stop();
//报错为:RuntimeException:stop failed
mediarecorder.setOnErrorListener(null);
mediarecorder.setOnInfoListener(null);
mediarecorder.setPreviewDisplay(null);
mediarecorder.stop();
} catch (IllegalStateException e) {
// TODO: handle exception
Log.i("Exception", Log.getStackTraceString(e));
}catch (RuntimeException e) {
// TODO: handle exception
Log.i("Exception", Log.getStackTraceString(e));
}catch (Exception e) {
// TODO: handle exception
Log.i("Exception", Log.getStackTraceString(e));
}
//added by ouyang end
mediarecorder.release();
mediarecorder = null;
if (mCamera != null) {
mCamera.release();
mCamera = null;
}
}
====================================================================================
作者:欧阳鹏 欢迎转载,与人分享是进步的源泉!
转载请保留原文地址:http://blog.csdn.net/ouyang_peng
今天在调用MediaRecorder.stop(),报错了,java.lang.RuntimeException: stop failed.
[html] view plain copy
E/AndroidRuntime(7698): Cause by: java.lang.RuntimeException: stop failed.
E/AndroidRuntime(7698): at android.media.MediaRecorder.stop(Native Method)
E/AndroidRuntime(7698): at com.tintele.sos.VideoRecordService.stopRecord(VideoRecordService.java:298)
报错代码如下:
[java] view plain copy
if (mediarecorder != null) {
mediarecorder.stop();
mediarecorder.release();
mediarecorder = null;
if (mCamera != null) {
mCamera.release();
mCamera = null;
}
}
stop()方法源代码如下:
[java] view plain copy
/**
* Stops recording. Call this after start(). Once recording is stopped,
* you will have to configure it again as if it has just been constructed.
* Note that a RuntimeException is intentionally thrown to the
* application, if no valid audio/video data has been received when stop()
* is called. This happens if stop() is called immediately after
* start(). The failure lets the application take action accordingly to
* clean up the output file (delete the output file, for instance), since
* the output file is not properly constructed when this happens.
*
* @throws IllegalStateException if it is called before start()
*/
public native void stop() throws IllegalStateException;
源代码中说了:Note that a RuntimeException is intentionally thrown to the application, if no valid audio/video data has been received when stop() is called. This happens if stop() is called immediately after start().The failure lets the application take action accordingly to clean up the output file (delete the output file, for instance), since the output file is not properly constructed when this happens.
现在,在mediarecorder.stop();这一句报错了,现在在mediarecorder.stop();这句之前加几句就不会报错了
mediarecorder.setOnErrorListener(null);
mediarecorder.setOnInfoListener(null);
mediarecorder.setPreviewDisplay(null);
改后代码如下:
[java] view plain copy
if (mediarecorder != null) {
//added by ouyang start
try {
//下面三个参数必须加,不加的话会奔溃,在mediarecorder.stop();
//报错为:RuntimeException:stop failed
mediarecorder.setOnErrorListener(null);
mediarecorder.setOnInfoListener(null);
mediarecorder.setPreviewDisplay(null);
mediarecorder.stop();
} catch (IllegalStateException e) {
// TODO: handle exception
Log.i("Exception", Log.getStackTraceString(e));
}catch (RuntimeException e) {
// TODO: handle exception
Log.i("Exception", Log.getStackTraceString(e));
}catch (Exception e) {
// TODO: handle exception
Log.i("Exception", Log.getStackTraceString(e));
}
//added by ouyang end
mediarecorder.release();
mediarecorder = null;
if (mCamera != null) {
mCamera.release();
mCamera = null;
}
}
====================================================================================
作者:欧阳鹏 欢迎转载,与人分享是进步的源泉!
转载请保留原文地址:http://blog.csdn.net/ouyang_peng
相关文章推荐
- 我的Android进阶之旅------>Android中MediaRecorder.stop()报错 java.lang.RuntimeException: stop failed.
- MediaRecorder start failed -19 java.lang.RuntimeException: start failed
- Error:Execution failed for task ':app:mergeDebugResources'. > Error: java.lang.RuntimeException: Som
- Android 录音,加权限还有错误:java.lang.RuntimeException: setAudioSource failed. onCallStateChanged获取不到来电号码
- Android问题:Test run failed: Instrumentation run failed due to 'java.lang.RuntimeException'
- Android 4.4.2 - java.lang.RuntimeException: Performing stop of activity that is not resumed
- Error:Execution failed for task ':app:mergeDebugResources'. > Error: java.lang.RuntimeException: Cru
- Error:Execution failed for task ':app:mergeDebugResources'. > Error: java.lang.RuntimeException: Cru
- java.lang.RuntimeException: stop failed.
- Android使用MediaRecorder录音导致java.lang.RuntimeException: start failed.
- 相机 android java.lang.RuntimeException: setParameters failed
- (Eclipse on linux 启动过程中报错)java.lang.RuntimeException: Widget disposed too early!
- java.lang.RuntimeException: file name is is too long ( > 100 bytes) 异常
- ERROR/AndroidRuntime(716): java.lang.SecurityException: Binder invocation to an incorrect interface
- FAILED: Hive Internal Error: java.lang.RuntimeException(Error while making MR scratch directory
- 严重: Dispatcher initialization failed java.lang.RuntimeException: java.lang.reflect.InvocationTargetException 问题解决
- ERROR/AndroidRuntime(716): java.lang.SecurityException: Binder invocation to an incorrect interface
- Android开发中java.lang.RuntimeException:错误的集中原因及解决办法
- java.lang.RuntimeException: startPreview failed
- java.lang.RuntimeException: file name is is too long ( > 100 bytes) 异常