使用 MediaRecorder#stop 时出现 java.lang.RuntimeException : stop failed.

标签 java android

这是我的full code ,这里是my project ,当我在 #onCreate 中使用 MediaRecorder#stop 时,它会引发

java.lang.RuntimeException: stop failed.
at android.media.MediaRecorder.stop(Native Method)
at ro.rotry.TestMr.onCreate(TestMr.java:39)
at android.app.Activity.performCreate(Activity.java:6237)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
at android.app.ActivityThread.-wrap11(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5417) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 

那么如何解决呢?

最佳答案

而不是这个:

    mr.setVideoSource(MediaRecorder.VideoSource.SURFACE);
    mr.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
    mr.setVideoSize(1920, 1080);
    mr.setVideoEncoder(MediaRecorder.VideoEncoder.H264);

尝试使用摄像机配置文件:

        try {

        camera.unlock();

        recorder.setPreviewDisplay(holder.getSurface());
        recorder.setCamera(camera);

        recorder.setOrientationHint(cameraRotationDegree);
        recorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
        recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
        recorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH));
        recorder.setVideoEncodingBitRate(5000000);
        recorder.setOutputFile(getFilesDir() + "/try.mp4");
        recorder.prepare();
        Thread.sleep(1000);
        recorder.start();

     }catch (IOException e) {
            e.printStackTrace();
        }

关于使用 MediaRecorder#stop 时出现 java.lang.RuntimeException : stop failed.,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37044964/

相关文章:

java - 构造函数参数 "this"从 Activity 但从 Fragment 工作

android - HereMaps 中的 map 标记方向

android - 无法使用 ndk-build 构建修改后的 android-fuse

android - 当应用程序进入后台时暂停线程

java - RESTeasy/JAXB 的 JSON 解析错误

java - 通过上下文对象的同步 getter 实现线程安全

java - 如何从 Eclipse IDE 获取当前 Activity 选项卡的文件名?

java - 无法从第三方 Web 服务获得响应

java - 单击按钮时应用程序崩溃

java - 无法使用 nexmo 或 thilio 发送短信