0

就我而言,我想拍照或捕捉视频,如果我创建单独的意图,实际上我可以做到这些。我的意思是我可以将相机打开为图像模式或视频模式,但不能在它们之间切换。这与我使用的意图过滤器有关吗?我应该怎么办?我如何在它们之间切换?

4

1 回答 1

0

我有同样的问题。在我认为放置一个按钮以在具有相同表面视图的同一个活动中录制视频之后,我为照片相机做了一个表面视图和一个活动,但我不知道这是否可能。嗯,我在Activity中写了这个方法来准备de MediaRecorder,取表面视图。

    public Boolean prepararCamaraVideo(){

    mMediaRecorder = new MediaRecorder();

    mCamera.unlock();
    mMediaRecorder.setCamera(mCamera);

    mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
    mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);

    state = MediaRecorderState.INITIALIZED;

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO)
        mMediaRecorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH));
    else { 
        mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
        mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
        mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.MPEG_4_SP);
    }

    state = MediaRecorderState.DATA_SOURCE_CONFIGURED;

    mOutputFile = Files.getExternalMediaFile(Files.MEDIA_TYPE_VIDEO).toString();
    mMediaRecorder.setOutputFile(mOutputFile);

    mMediaRecorder.setPreviewDisplay(mCameraPreview.getHolder().getSurface());

    try {
        mMediaRecorder.prepare();
    } catch (IllegalStateException e) {
        Log.d("Video", "IllegalStateException preparing MediaRecorder: " + e.getMessage());
        releaseMediaRecorder();
        return false;

    } catch (IOException e) {
        Log.d("Video", "IOException preparing MediaRecorder: " + e.getMessage());
        releaseMediaRecorder();
        return false;
    }
    return true;

}

这个命令 mMediaRecorder.setPreviewDisplay(mCameraPreview.getHolder().getSurface()); 获取摄像机的表面。

最后是录制视频的方法。

    public void grabaVideo(View v) {
    if (state!=MediaRecorderState.RECORDING){
        if (prepararCamaraVideo()) {
            mMediaRecorder.start();
            state = MediaRecorderState.RECORDING;
            Toast.makeText(getApplicationContext(), getString(R.string.capturing_video), Toast.LENGTH_SHORT).show();                
        } else {
            // prepare didn't work, release the camera
            releaseMediaRecorder();
            // inform user
        }
    }
    else{
        mMediaRecorder.stop();  // stop the recording
        releaseMediaRecorder(); // release the MediaRecorder object
        mCamera.lock();         // take camera access back from MediaRecorder

        state = MediaRecorderState.INITIAL;
        Toast.makeText(getApplicationContext(), getString(R.string.video_stored_in) + " " + mOutputFile, Toast.LENGTH_SHORT).show();

    }

}

我希望能帮助你。

于 2013-04-09T16:02:05.510 回答