Android MediaRecorder运行时异常启动()/损坏的视频



我有活动与MediaRecorder的工作在android 2.3.6。现在我在三星Galaxy S2(4.044)和mRecorder.start()上尝试它,给所有摄像机配置文件RuntimeException。它只能支持480P,但视频会被线条破坏。我试过这个方法。

Camera.Parameters params = camera.getParameters();
params.setFocusMode(Camera.Parameters.FOCUS_MODE_INFINITY);
params.set("cam_mode",1);
camera.setParameters(params);

但是它不起作用。还有其他解决方案吗?

手机闪过android,可能是这个问题?

我的代码
    @Override
    public void surfaceCreated(SurfaceHolder holder) {
        if (camera == null) {
            camera = Camera.open();
        }
        Camera.Parameters params = camera.getParameters();
        params.setFocusMode(Camera.Parameters.FOCUS_MODE_INFINITY);
        params.set("cam_mode",1);
        camera.setParameters(params);
        if (camera != null) {
            try {
                camera.setPreviewDisplay(holder);
                camera.startPreview();
            } catch (IOException e) {
                e.printStackTrace();
            }
        } else {
            Toast.makeText(getApplicationContext(), "Camera not available.", Toast.LENGTH_LONG).show();
            finish();
        }
    }
    public void startRecording() throws IOException {
            camera.stopPreview();
            prepareRecord();
            recordButton.setImageResource(R.drawable.record_button_stop);
            startRecord();
        }
    public void prepareRecord() throws IllegalStateException, IOException {
        if (camera == null) {
            camera = Camera.open();
        }
        if (mRecorder == null) {
            mRecorder = new MediaRecorder();
        }
        camera.lock();
        camera.unlock();
        mRecorder.setCamera(camera);
        mRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
        mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
        CamcorderProfile cProfile = CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH);
        mRecorder.setProfile(cProfile);
        mRecorder.setPreviewDisplay(surfaceHolder.getSurface());
        mRecorder.setOutputFile(pathName + "/" + fileName + ".mp4");
        mRecorder.prepare();
    }
    public void startRecord() {
        if (recording == false) {
            mRecorder.start();
            recording = true;
        }
    }

LogCat

02-21 01:49:38.505: E/AndroidRuntime(4210): FATAL EXCEPTION: main
02-21 01:49:38.505: E/AndroidRuntime(4210): java.lang.RuntimeException: start failed.
02-21 01:49:38.505: E/AndroidRuntime(4210):     at android.media.MediaRecorder.native_start(Native Method)
02-21 01:49:38.505: E/AndroidRuntime(4210):     at android.media.MediaRecorder.start(MediaRecorder.java:704)
02-21 01:49:38.505: E/AndroidRuntime(4210):     at com.olos.videogpsrecorder.VideoRecorderActivity.startRecord(VideoRecorderActivity.java:401)
02-21 01:49:38.505: E/AndroidRuntime(4210):     at com.olos.videogpsrecorder.VideoRecorderActivity.startRecording(VideoRecorderActivity.java:343)
02-21 01:49:38.505: E/AndroidRuntime(4210):     at com.olos.videogpsrecorder.VideoRecorderActivity$1.onClick(VideoRecorderActivity.java:129)
02-21 01:49:38.505: E/AndroidRuntime(4210):     at android.view.View.performClick(View.java:3511)
02-21 01:49:38.505: E/AndroidRuntime(4210):     at android.view.View$PerformClick.run(View.java:14105)
02-21 01:49:38.505: E/AndroidRuntime(4210):     at android.os.Handler.handleCallback(Handler.java:605)
02-21 01:49:38.505: E/AndroidRuntime(4210):     at android.os.Handler.dispatchMessage(Handler.java:92)
02-21 01:49:38.505: E/AndroidRuntime(4210):     at android.os.Looper.loop(Looper.java:137)
02-21 01:49:38.505: E/AndroidRuntime(4210):     at android.app.ActivityThread.main(ActivityThread.java:4575)
02-21 01:49:38.505: E/AndroidRuntime(4210):     at java.lang.reflect.Method.invokeNative(Native Method)
02-21 01:49:38.505: E/AndroidRuntime(4210):     at java.lang.reflect.Method.invoke(Method.java:511)
02-21 01:49:38.505: E/AndroidRuntime(4210):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
02-21 01:49:38.505: E/AndroidRuntime(4210):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
02-21 01:49:38.505: E/AndroidRuntime(4210):     at dalvik.system.NativeStart.main(Native Method)

CamcorderProfile cProfile = CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH); mRecorder.setProfile(cProfile);将上面两行替换为下面一行。mRecorder.setProfile(CamcorderProfile.get(mCurrentCameraId, CamcorderProfile.QUALITY_720P));这里mCurrentCameraId是相机Id

最新更新