0

Android 2.3.6で動作するMediaRecorderを使用したアクティビティがあります。今、Samsung 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);

しかし、うまくいきません。他の解決策はありますか?

電話がアンドロイドをフラッシュしました。これが問題でしょうか?

私のコード

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

1 に答える 1

0

CamcorderProfile cProfile = CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH); mRecorder.setProfile(cProfile);上の 2 行を下の行に置き換えます。 mRecorder.setProfile(CamcorderProfile.get(mCurrentCameraId, CamcorderProfile.QUALITY_720P));ここで mCurrentCameraId はカメラ ID です

于 2016-09-15T11:31:40.467 に答える