android 媒体记录器异常
我尝试使用 MediaRecorder 类录制视频,但出现异常:无法获取相机参数。准备失败。
这是我的代码:
camera = Camera.open();
recorder = new MediaRecorder();
recorder.setCamera(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();
有什么想法吗?
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.setCamera(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 ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
调用
您需要解锁相机,请尝试在 recorder.setCamera 之前
You need unlock camera, try to call
before recorder.setCamera
我注意到您没有包含 setAudioSource 或 setFrameRate - 有时 MediaRecorder 对这些设置很挑剔。
另外,我通常会看到在其他项目之前设置了预览显示。
你有这个的 logcat 转储吗?
仅供参考,我注意到让视频在某些设备上工作是很棘手的 - MediaRecorder 准备的时间很特殊,有时需要额外的代码来延迟。
http://code.google.com/p/android/issues/详情?id=5050
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