日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Android >内容正文

Android

我的Android进阶之旅------gt;Android中MediaRecorder.stop()报错 java.lang.RuntimeException: stop failed....

發(fā)布時間:2025/4/16 Android 65 豆豆
生活随笔 收集整理的這篇文章主要介紹了 我的Android进阶之旅------gt;Android中MediaRecorder.stop()报错 java.lang.RuntimeException: stop failed.... 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

今天在調用MediaRecorder.stop(),報錯了,java.lang.RuntimeException: stop failed.

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)


報錯代碼如下:

if (mediarecorder != null) {mediarecorder.stop();mediarecorder.release();mediarecorder = null;if (mCamera != null) {mCamera.release();mCamera = null;}}


stop()方法源代碼如下:

/*** 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);

改后代碼如下:

if (mediarecorder != null) {//added by ouyang starttry {//下面三個參數必須加,不加的話會奔潰,在mediarecorder.stop();//報錯為:RuntimeException:stop failedmediarecorder.setOnErrorListener(null);mediarecorder.setOnInfoListener(null); mediarecorder.setPreviewDisplay(null);mediarecorder.stop();} catch (IllegalStateException e) {// TODO: handle exceptionLog.i("Exception", Log.getStackTraceString(e));}catch (RuntimeException e) {// TODO: handle exceptionLog.i("Exception", Log.getStackTraceString(e));}catch (Exception e) {// TODO: handle exceptionLog.i("Exception", Log.getStackTraceString(e));}//added by ouyang endmediarecorder.release();mediarecorder = null;if (mCamera != null) {mCamera.release();mCamera = null;}}



====================================================================================

? 作者:歐陽鵬? 歡迎轉載,與人分享是進步的源泉!

? 轉載請保留原文地址:http://blog.csdn.net/ouyang_peng

====================================================================================



總結

以上是生活随笔為你收集整理的我的Android进阶之旅------gt;Android中MediaRecorder.stop()报错 java.lang.RuntimeException: stop failed....的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。