如何打开相机,然后切换到图像模式(反之亦然) [英] How to open camera then switch to Image mode (vice versa)
问题描述
在我来说,我想拍照或拍摄视频,其实我能做到这些,如果我创建单独的意图。我的意思是我可以打开相机图像模式或视频模式,但可以在它们之间切换。这是涉及到我使用意图过滤器?我该怎么办?我如何在它们之间进行切换?
In my case I want to take photo or capture video, actually I can do these if I create separate intents. I mean I can open camera as image mode or video mode but can not switch between them. Is this related to intent filters which I use? What should I do? How do I switch between them?
推荐答案
我有同样的问题。我做了一个面视图和活动相片相机,我以为把一个按钮后,记录在同一个活动的同一表面上观看视频,但我不知道这是否是可能的。好了,我的活动,以prepare日MediaRecorder写了这个方法,并采取表面观。
I had the same problem. I did a surface view and an Activity for a photo camera after I thought put a button to record a video in the same Activity with the same surface view but I don´t know if it was possible. Well, I wrote this method in the Activity to prepare de MediaRecorder and take the surface view.
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.set previewDisplay(mCamera preview.getHolder()getSurface());得到的表面的摄像机
This command mMediaRecorder.setPreviewDisplay(mCameraPreview.getHolder().getSurface()); get the surface for the Video Camera.
最后的方法来记录视频。
Finally the method to Record the video.
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();
}
}
我希望能帮助你。
I hope to help you.
这篇关于如何打开相机,然后切换到图像模式(反之亦然)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!