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?
Asked
Active
Viewed 2,511 times
0
-
Do you need to get camera by using intent or can you use android’s camera class ? – Talha Dec 25 '12 at 08:55
-
I used this way because its management was easy. Do you have any tutorial about it? – Mustafa Güven Dec 25 '12 at 09:04
-
But you cant switch the mode by using this way. – Talha Dec 25 '12 at 09:06
-
http://androiddevblog.blogspot.com/2010/07/controlling-android-camera.html, i hope it gives you some ideas – Talha Dec 25 '12 at 09:06
-
http://marakana.com/forums/android/examples/39.html Taking picture is ok how about capturing a video? – Mustafa Güven Dec 25 '12 at 09:15
-
you can look at this article http://www.techrepublic.com/blog/app-builder/a-surveillance-android-app-developing-a-continuous-video-recorder/821 – Talha Dec 25 '12 at 09:19
-
I also don't think it is possible by this way.Look.. http://stackoverflow.com/questions/6476084/how-to-capture-video-and-photo-at-same-time-in-an-activity – ridoy Dec 25 '12 at 09:22
1 Answers
0
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;
}
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.

Pedro
- 31
- 4