I'm trying to create a simple video recorder and here's my code in order that I'm calling it:
protected boolean prepareForVideoRecording() {
try {
mCamera.unlock();
mMediaRecorder = new MediaRecorder();
mMediaRecorder.setCamera(mCamera);
mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
mMediaRecorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH));
mMediaRecorder.setOutputFile(getOutputMediaFile1(MEDIA_TYPE_VIDEO).toString());
mMediaRecorder.setPreviewDisplay(mPreview.getHolder().getSurface());
try {
mMediaRecorder.prepare();
Toast.makeText(getContextOfMainFragment(), "Prepared!", Toast.LENGTH_SHORT).show();
} catch (IllegalStateException e) {
Log.e(TAG,"IllegalStateException when preparing MediaRecorder "+ e.getMessage());
e.getStackTrace();
releaseMediaRecorder();
return false;
} catch (IOException e) {
Log.e(TAG,"IOException when preparing MediaRecorder "+ e.getMessage());
e.getStackTrace();
releaseMediaRecorder();
return false;
}
return true;
} catch (Exception e) {
return false;
}
}
Please ignore the toast messages, I kinda use them sometimes for debugging. Next, the only thing is left is calling mMediaRecorder.start() I do this on a button click. In fact, I've added 2 buttons, 1st button calls this above method, the other button makes the start call. I'm sure this same code worked for me once, I don't know why isn't it working anymore.
I added a try catch around my mMediaRecorder.start() call with an IllegalStateException and here's what I got:
04-09 10:38:18.350: E/MediaRecorder(29678): start failed: -38
04-09 10:38:18.350: E/VideoTut_Main(29678): Illegal state exception with MediaRecorder.Start() : null