android mediarecorder exception
I try to use the MediaRecorder class to record a video but I get an exception : failed to get Camera parameters. Prepare failed.
Here's my code :
camera = Camera.open();
recorder = new MediaRecorder();
recorder.se开发者_JS百科tCamera(camera);
recorder.setVideoSource(VideoSource.CAMERA);
recorder.setPreviewDisplay(m_holder.getSurface());
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setVideoEncoder(MediaRecorder.VideoEncoder.DEFAULT);
recorder.setMaxDuration(10000);
recorder.setOutputFile(file.getPath());
recorder.prepare();
Any idea ?
You need unlock camera, try to call
camera.unlock();
before recorder.setCamera
I'm noticing that you didn't include setAudioSource or setFrameRate - sometimes the MediaRecorder is picky about these setups.
Also, I have typically seen the previewDisplay set before the other items.
Do you have a logcat dump for this?
FYI, I have noticed that getting video to work with some devices is tricky - the timing for the MediaRecorder prepare is particular, and sometimes requires extra code for delay.
http://code.google.com/p/android/issues/detail?id=5050
精彩评论