开发者

android mediarecorder exception

开发者 https://www.devze.com 2023-01-04 07:12 出处:网络
I try to use the MediaRecorder class to record a video but I get an exception : failed to get Camera parameters. Prepare failed.

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号