如何使用setCamera(MediaRecorder)?
根据Android SDK,MediaRecorder.setCamera可以用于回收现有的相机实例进行视频捕获和预览,而无需重置预览。我无法找到任何示例,并且我所有的尝试都是徒劳的:我要么得到错误的状态异常,要么 MediaRecorder.prepare 失败。
- 有谁知道这个方法是否可用?
- 那我该如何使用它呢?
- 网上有可用的示例吗?
According to Android SDK MediaRecorder.setCamera can be used to recycle the existing camera instance for video capture and preview without resetting the preview. I was not able to find any sample, and all my attempts were futile: I either get the wrong state exception, or MediaRecorder.prepare fails.
- Does anyone know if this method usable at all?
- How can I use it then?
- Any samples available on the Web?
For reference:
http://developer.android.com/reference/android/media/MediaRecorder.html#setCamera(android.hardware.Camera)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我遇到了同样的问题并发现了它是如何工作的。有些事情必须正确完成。首先,您应该从 安卓文档。
命令的工作顺序如下。
完整的示例可以在此处。
I ran into the same problem and found out how it can work. Some things have to be done correctly. First you should check the state chart from the android document.
A working order of commands is as follows.
A full example can be found here.
Android 相机应用程序源提供了最好的例子。经过一番调查,我发现
recorder.setCamera(camera)
应在实例化 MediaRecorder 之后立即调用,或者至少在对其应用任何设置之前。在调用setCamera()
之前应用任何设置(setVideoSource()
等)都会导致错误。The Android Camera app source provides the best example. After some investigation, I discovered that
recorder.setCamera(camera)
should be called immediately after instantiation of theMediaRecorder
, or at least before any settings are applied to it. Applying any settings (setVideoSource()
, etc.) before callingsetCamera()
results in an error.我从@lyron 得到了提示。
首先,打开前置摄像头。
我需要像上面一样使用前置摄像头。
并且不要忘记解锁相机。
如果不这样做,您将看到下面的错误。
第二,先设置相机,然后再像这样设置其他。
有人说应该在准备之前调用 setCamera() ()。
但我看到我的代码正在运行。
I got hint from @lyron.
First, open the front camera.
I need to use the front camera as above.
And DON'T FORGET to UNLOCK the camera.
If you don't, you'll see errors below.
Second, set the camera before setting the others like this.
Someone says that setCamera() should be called before prepare().
But I'm watching my code is working.
创建 mediarecorder 实例后,您是否尝试过使用以下功能?
//解锁相机以允许另一个进程访问它。
//设置用于录制的相机。使用此函数可以在预览和//捕获模式之间快速切换,而无需拆卸相机对象。
Have you tried to use the following functions after creating an instance of mediarecorder?
//Unlocks the camera to allow another process to access it.
//Sets a Camera to use for recording. Use this function to switch quickly between preview and //capture mode without a teardown of the camera object.
我启动了我的 MediaRecorder:
但不是这样的:
(headbang)哈哈..现在我的问题是用于预览的 kalydascope.. 是时候搜索互联网了..
希望这对某人有帮助。
I had my MediaRecorder initiated:
but not like this :
(headbang) haha.. now my issue is a kalydascope for a preview.. time to search the interwebs..
hopefully this helped someone.
我找到了 2 个您可能会觉得有用的链接。 Android 相机 git 存储库 和 MediaRecorder 示例
I found 2 links you may find useful. Android Camera git repo and a MediaRecorder example