我的Android进阶之旅------>Android中MediaRecorder.stop()报错 java.lang.RuntimeException: stop failed.
2023-09-27 14:29:23 时间
今天在调用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 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 | 音视频方向进阶路线及资源合集 但是系统相机和系统控件VideoView的局限性都是可定制型太差,系统相机的图像分辨率,视频码率以及VideoView的进度条等.
字节卷动 You will never know how excellent you are unless you impel yourself once.
相关文章
- AndroidStudio 3.0中之后无法打开DDMS [Android Device Monitor] 问题
- android-----带你一步一步优化ListView(一)
- android java epson串口打印机
- Google证实下一版Android不再使用Oracle专属的Java API
- android 因为没有赋null,报以下错:has already been added to the window manager
- 2021年Android开发者常见面试题,深度解析,值得收藏
- 2021年Android技术下半场在哪?终局之战
- Android应用中使用AsyncHttpClient来异步网络数据
- 【AS】Error:Android Gradle plugin requires Java 11
- Android 自己的自动化测试(2)依据ID查找对象(java)
- android 如何分析java.lang.IllegalArgumentException: Cannot draw recycled bitmaps异常
- Android 监听双卡信号强度(附完整代码)
- android开发之AlertDialog点击按钮之后不消失 分类: android 学习笔记 2015-07-15 18:07 89人阅读 评论(0) 收藏
- Android 中的 Effective Java(速查表)
- WebRTC在Windows、Linux、Macos和Android下的下载及编译
- Android ViewFlipper触摸动画
- 解决错误ERROR: No suitable Java found. In order to properly use the Android Developer Tools,…
- Android AudioManager控制系统声音的流程
- Android中添加两个(多个)FileProvider节点问题
- 【Android 电量优化】电量优化 ( 耗电量测试 | Battery Historian 简介 | apt 源更新 | Docker 安装 | Battery Historian 安装 )
- React Native 控件之 Modal 详解 - Android/iOS 双平台通用
- 【错误记录】Android 中调用 Process 命令行执行指令 ( java.lang.IllegalThreadStateException: process hasn‘t exited )
- Android Fragment详解
- Android kotlin和java反编译后的smali 有什么区别?
- 我的Android进阶之旅------>Java全角半角的转换方法
- 我的Android进阶之旅------>解决AES加密报错:java.security.InvalidKeyException: Unsupported key size: 18 bytes
- 我的Android进阶之旅------>Android编译错误java.util.zip.ZipException: duplicate entry的解决方法
- 我的Android进阶之旅------>对Java中注释/**@hide*/的初步认识
- 在Ubuntu上为Android系统内置Java应用程序测试Application Frameworks层的硬件服务