I have one question,
When I use the aurio recording on my program, it works fine, but when i try the video recording, my .3gp file is empty (0 bytes).
Can you please tell me why?
Here is a part of my code for the video recording which does not work:
protected void startRecording() throws IOException
{
mrec = new MediaRecorder(); // Works well
mrec.setVideoSource(MediaRecorder.VideoSource.CAMERA);
mrec.setAudioSource(MediaRecorder.AudioSource.MIC); //Works well
mrec.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4); //Works well with OutputFormat.THREE.GPP
mrec.setVideoSize(100, 100);
mrec.setVideoFrameRate(5);
mrec.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); // Works well
mrec.setVideoEncoder(MediaRecorder.VideoEncoder.MPEG_4_SP);
mrec.setOutputFile("/sdcard/test5.3gp"); //Works well with test5.mp4
mrec.prepare(); // Works well for the audio recording
mrec.start(); // Works well for the audio recording
}
Video recording it turns out is not that simple.
First you will need to unlock the handle to the camera object and then set the camera to the recorder.
Note: you will need to call the
setCameraright after you callunlockand before you call any other recorder API’s, else you will end up with a illegal state exception.Next you will need to setup the preview display surface with the recorder. This basically acts like the video input to the recorder, i.e., any video data in the preview surface it is taken as input to the video recording.
If you need help on how to get the preview up on the camera, check this link.
Instead of setting formats individually, use the
getProfileandsetProfileAPI’s on the recoder.One last thing, the video resolution that is set to the recorder needs to be in sync with the resolution of the preview surface. If your preview surface is VGA then make sure you performing the recording with a VGA resolution.