views:

926

answers:

3

Hi,

I am trying to capture video and the routine throws an exception when the execution reaches recorder.prepare() statement:

private void recordVideoStart(){
 if(recorder != null)
 {
  recorder.stop();
  recorder.release();
 }
 File file = new File("/sdcard/videoTest.3gpp");
 try {
  file.createNewFile();
 } catch (IOException e) {
  // TODO Auto-generated catch block
  e.printStackTrace();
 }


 recorder = new MediaRecorder();
 recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
 recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
 recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
 recorder.setOutputFile(file.getAbsolutePath());
 recorder.setVideoSize(176, 144);
 recorder.setVideoFrameRate(15);
 //recorder.setVideoEncoder(MediaRecorder.VideoEncoder.MPEG_4_SP);
 recorder.setVideoEncoder(MediaRecorder.VideoEncoder.DEFAULT);
 recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
 recorder.setPreviewDisplay(videoPreview.getSurface());

 try {
  recorder.prepare();
 } catch (IllegalStateException e) {
  // TODO Auto-generated catch block
  e.printStackTrace();
 } catch (IOException e) {
  // TODO Auto-generated catch block
  e.printStackTrace();
 }
 recorder.start();
}

Looking the LogCat I noticed the line "Camera is not available".

Does anyone know what could be wrong here and how to enable video capture?

Thanks!

A: 

Hi

You need to set the a Camera to the recorder.

recorder.setCamera(Camera.open());

A: 

have you added in AndroidManifest.xml uses-permission android:name="android.permission.CAMERA"

lke
A: 

Make sure the following permissions are there in your manifest. WRITE_EXTERNAL_STORAGE is required for it to write onto our SD card

Namratha