views:

6888

answers:

7

Hi,

I would like to create a video recorder and so far haven't figured out how to set parameters in order to successfully go through MediaRecorder.prepare() method.

Executing the following method

public void start() throws IOException{
 String state = android.os.Environment.getExternalStorageState();
 if(!state.equals(Environment.MEDIA_MOUNTED))
 {
  throw new IOException("SD card is not mounted. It is " + state + ".");
 }
 File directory = new File(path).getParentFile();
 if(!directory.exists() && !directory.mkdirs())
 {
  throw new IOException("Path to file could not be created.");
 }

 recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
 recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
 recorder.setVideoEncoder(MediaRecorder.VideoEncoder.H263);
 recorder.setVideoFrameRate(15);
 recorder.setVideoSize(176, 144);
 recorder.setOutputFile(path);
 recorder.prepare();
 recorder.start();
 this.state = VideoRecorderState.STATE_RECORDING;
}

it throws an exception on line recorder.prepare().

Does anyone know how to set parameters in order to be able to capture video?

Thanks!

+2  A: 

Maybe the Camera application's source helps you debug this.

Josef
A: 

This could be a permissions error. Do you have the android.permission.CAMERA permission set in your AndroidManifest file?

+1  A: 

Hi niko!

Here is a snippet that works:

m_recorder = new MediaRecorder(); m_recorder.setPreviewDisplay(m_BeMeSurface); m_recorder.setAudioSource(MediaRecorder.AudioSource.MIC); m_recorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT); m_recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); m_recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); m_recorder.setVideoEncoder(MediaRecorder.VideoEncoder.MPEG_4_SP); m_recorder.setMaxDuration((int) MAX_TIME); m_recorder.setOnInfoListener(m_BeMeSelf); m_recorder.setVideoSize(320, 240); m_recorder.setVideoFrameRate(15); m_recorder.setOutputFile(m_path);

m_recorder.prepare(); m_recorder.start();

THE most important thing is the surface. You don't have it, so without it it fails.

Regards

BeMeCollective

BeMeCollective
A: 

Hi

I am not able to record the video . sample i got can able to record the audio but not the video

Does anyone has the sample programme to record the video with audio , it would be of gr8 help

Thanks in advance Vish

vishnu
Perhaps if you ask a new question you will receive a better response.
Paul Lammertsma
+1  A: 

@josef : In my experience it segfaults. There's no exception, just a core dump, which is very unhelpful if you're not an android core developer.

rabidsnail
+1  A: 

Have you checked this out?

http://code.google.com/p/android/issues/detail?id=5050

These guys suggest that it is a timing issue, and that the MediaRecorder state machine may require some delay (hardware dependent?) between states.

It would be nice if there were callbacks for when each state was fully achieved - then we could just put prepare in that.

ajaxlex
A: 

I am exactly answering this question in the following tutorial: http://integratingstuff.wordpress.com/2010/10/18/writing-code-that-captures-videos-on-android/

The reason why your code is failing on prepare() is because you didnt set all the necessary properties. For example, you also need to set maxDuration.

Integrating Stuff