Mediarecorder开始失败19

时间:2014-08-17 13:22:47

标签: android

我的代码工作android 2.33但是android 4.11捕获错误mediarecorder启动失败19在mediarecorder.start()行为什么我不明白

8-17 18:07:57.468  11453-11453/com.example.SelfVideocaptureTest E/MediaRecorderJNI﹕ Application lost the surface
08-17 18:08:24.577      89-3117/? E/CameraSource﹕ Camera connection could not be established.
08-17 18:08:24.577  11453-11453/com.example.SelfVideocaptureTest E/MediaRecorder﹕ start failed: -19
08-17 18:08:24.581  11453-11453/com.example.SelfVideocaptureTest E/AndroidRuntime﹕ FATAL EXCEPTION: main
    java.lang.RuntimeException: start failed.
            at android.media.MediaRecorder.start(Native Method)
            at com.example.SelfVideocaptureTest.MyActivity.onClick(MyActivity.java:146)
            at android.view.View.performClick(View.java:4084)
            at android.view.View$PerformClick.run(View.java:16966)
            at android.os.Handler.handleCallback(Handler.java:615)
            at android.os.Handler.dispatchMessage(Handler.java:92)
            at android.os.Looper.loop(Looper.java:137)

谁能帮帮我???这是我的代码

private boolean prepareVideoRecorder()             {

            mediaRecorder = new MediaRecorder();

            if (Build.VERSION.SDK_INT < 14)
                    camera.unlock();
            mediaRecorder.setCamera(camera);
            mediaRecorder.setPreviewDisplay(preView.getHolder().getSurface());
            mediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
            mediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);

            mediaRecorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_LOW));
            mediaRecorder.setOutputFile(getOutputMediaFile(MEDIA_TYPE_VIDEO).getAbsolutePath());
            mediaRecorder.setPreviewDisplay(preView.getHolder().getSurface());
            try
                {
                    mediaRecorder.prepare();
                } catch (IOException e)
                {
                    e.printStackTrace();
                    releaseMediaRecorder();
                    return false;
                }
            return true;
        }

    @Override
    public void onClick(View view)
        {
            if (isRecording)
                {
                    mediaRecorder.stop();
                    releaseMediaRecorder();
                    if (Build.VERSION.SDK_INT < 14)
                        camera.lock();
                    button.setText("Capture");
                    isRecording = false;
                } else if (prepareVideoRecorder())
                {
                    mediaRecorder.start();
                    button.setText("Stop");
                    isRecording = true;
                } else
                {
                    releaseMediaRecorder();
                    Toast.makeText(getBaseContext(), "cannot record", 0).show();
                }
        }

我看到了这些页面

2 个答案:

答案 0 :(得分:1)

我也遇到了同样的问题并且看了所有这些答案=(。尝试过一百万件事......以及设置MediaRecorder的不同方法。

我刚刚开始工作,这是因为我没有打电话 - &gt;

android.hardware.Camera.unlock()

在顶部阅读捕捉视频部分:https://developer.android.com/guide/topics/media/camera.html

我注意到您正在调用解锁,但仅限于低于14的版本?也许需要为所有版本调用它?

答案 1 :(得分:0)

根据我所做的研究,当MediaRecorder#setVideoSize()

设置的视频大小出现问题时,会出现错误代码-19