在我来说,我想拍照或拍摄视频,其实如果我创建独立的意图,我可以做这些。 我的意思是,我可以打开相机的图像模式或视频模式,但它们之间不能切换。 这是涉及到我使用的意图过滤器? 我该怎么办? 如何在两者之间切换?
Answer 1:
我有同样的问题。 我做了一个表面视图和活动相片相机,我以为把一个按钮后,记录与相同表面观点相同活动的视频,但我不知道这是否是可能的。 嗯,我在写信的活动这种方法来准备去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();
}
}
我希望能帮助你。
文章来源: How to open camera then switch to Image mode (vice versa)