0

我有适用于 android 2.3.6 的 MediaRecorder 活动。现在我在三星 Galaxy S2 (4.044) 和 mRecorder.start() 上尝试使用所有 CamcorderProfiles 给 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;
        }
    }

日志猫

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)
4

1 回答 1

0

CamcorderProfile cProfile = CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH); mRecorder.setProfile(cProfile);用下面的行替换上面的两行。 mRecorder.setProfile(CamcorderProfile.get(mCurrentCameraId, CamcorderProfile.QUALITY_720P));这里 mCurrentCameraId 是相机 ID

于 2016-09-15T11:31:40.467 回答