在 Android 上使用两个摄像头:“无法连接到摄像头服务”
我在访问两个摄像头(同时访问前置摄像头和后置摄像头)时遇到问题。 当打开一台相机时它就可以工作。 当我先关闭然后再打开时,它就可以工作。 当我尝试打开第二个摄像头而第一个摄像头仍在显示图像时,它会出现以下异常。
E/AndroidRuntime(32325): FATAL EXCEPTION: main
E/AndroidRuntime(32325): java.lang.RuntimeException: Fail to connect to camera service
E/AndroidRuntime(32325): at android.hardware.Camera.native_setup(Native Method)
E/AndroidRuntime(32325): at android.hardware.Camera.<init>(Camera.java:265)
E/AndroidRuntime(32325): at android.hardware.Camera.open(Camera.java:226)
E/AndroidRuntime(32325): at com.example.videostreamer.MainActivity$CameraHandler.start(MainActivity.java:116)
E/AndroidRuntime(32325): at com.example.videostreamer.MainActivity$2.onClick(MainActivity.java:74)
E/AndroidRuntime(32325): at android.view.View.performClick(View.java:2532)
E/AndroidRuntime(32325): at android.widget.CompoundButton.performClick(CompoundButton.java:99)
在文档中我发现了这样一句话:
公共静态相机打开(intcameraId)
自:API 级别 9 创建一个新的 Camera 对象来访问特定的硬件相机。 使用完相机后必须调用release(),否则相机会一直保留 锁定且不可用于其他应用程序。 对于特定的应用程序,一次只能有一个处于活动状态的 Camera 对象 硬件摄像头。
..但我只有一个硬件相机的相机对象,我想为第二个设备创建第二个对象。
- 有谁知道这是否可行(我使用的是Android 2.3.3)?
- 地方:android.hardware.Camera.native_setup(Native Method) 可能表明可能是硬件/驱动程序限制 - 我正在使用 HTC Sensation。
I'm having troubles in accessing both (front and rear cameras at the same time).
When turn on one camera it works.
When i turn off first and turn on second it works.
It gives following exception when i'm trying to turn on second camera while the first one is still showing the image.
E/AndroidRuntime(32325): FATAL EXCEPTION: main
E/AndroidRuntime(32325): java.lang.RuntimeException: Fail to connect to camera service
E/AndroidRuntime(32325): at android.hardware.Camera.native_setup(Native Method)
E/AndroidRuntime(32325): at android.hardware.Camera.<init>(Camera.java:265)
E/AndroidRuntime(32325): at android.hardware.Camera.open(Camera.java:226)
E/AndroidRuntime(32325): at com.example.videostreamer.MainActivity$CameraHandler.start(MainActivity.java:116)
E/AndroidRuntime(32325): at com.example.videostreamer.MainActivity$2.onClick(MainActivity.java:74)
E/AndroidRuntime(32325): at android.view.View.performClick(View.java:2532)
E/AndroidRuntime(32325): at android.widget.CompoundButton.performClick(CompoundButton.java:99)
In the documentaion i found a phrase that says:
public static Camera open (int cameraId)
Since: API Level 9
Creates a new Camera object to access a particular hardware camera.
You must call release() when you are done using the camera, otherwise it will remain
locked and be unavailable to other applications.
Your application should only have one Camera object active at a time for a particular
hardware camera.
.. but i'm having only one Camera object for one hardware camera and I wanted to create second object for second device.
- Does anybody know if this is possible (I'm using Android 2.3.3)?
- The place: android.hardware.Camera.native_setup(Native Method) can suggest that probably it is hardware/driver limitation - I'm using HTC Sensation.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这个问题基本上说它不能已经完成了,但可能会有一些黑客行为。 Google 群组没有回应,这表明我很可能不会。 此处是另一个无响应在谷歌群组上发帖。 这里是另一篇讨论如何使用两个摄像头的帖子同一时间。
所以我最初的回答是否定的,这是不可能的。但可能有一些解决方法,您可能必须自己找到它,因为它还没有被发现:)。
编辑 11/21/11:不幸的是,我发现了进一步的证据,证明它无法完成,来自 Sprint/HTC 的官方 此处。我知道您使用的是 Sensation,这是 EVO 4g,但我确信它仍然适用。
This question basically says it cannot be done, but there may be some hack. This lack of response from google groups tells me most likely not. Here is another no-response post on google groups. Here is another post discussing the use of two cameras at the same time.
So my initial answer is no, it is not possible. BUT there may be some workaround, you just may have to find it yourself because it isn't discovered yet :).
EDIT 11/21/11: Unfortunately I found even further proof that it cannot be done, official from Sprint/HTC here. I realize you are using a Sensation, and this is an EVO 4g, but I'm sure it still applies.
只要硬件支持,两台相机都可以一起启动。首先,您需要找到您的手机使用的特定 SoC。您可以使用命令
Chech 字段 [ro.board.platform] 找到此信息,对于 Nexus 6,它会返回
现在您需要检查该芯片组在硬件中是否具有双 ISP 功能。对于 Qualcomm snapdragon 芯片组,您可以在此处找到它。对于三星 Exynos,您可以在此处找到它。现在,如果您的设备支持双摄像头并安装了最新的操作系统,那么您可以使用此应用程序(参考) 由 Jens 验证双摄像头是否工作。它应该可以工作,它可以在我的 Nexus 6 上工作。
视频:http://youtu.be/lt8N1Lpa9Zw
谢谢,Jai
Both cameras can be launched together as long as the hardware supports it. First you need to find the specific SoC used by your phone. You can find this by using the command
Chech the field [ro.board.platform], For Nexus 6 it returns
Now you would need to check if this chipset has dual-ISP capability in hardware. For Qualcomm snapdragon chipsets you can find it here. For Samsung Exynos you can find it here. Now if your device supports dual camera and has latest OS installed in it, then you can use this application (ref) developed by Jens to verify if the dual camera works. It should probably work, it does work on my Nexus 6.
Video: http://youtu.be/lt8N1Lpa9Zw
Thanks, Jai
我也想做同样的事情,但无法实现,它的android操作系统的限制。
您必须释放连接的相机对象才能被另一个对象访问。
访问 AudioRecord 类时也会遇到同样的问题,在释放第一个类之前,您无法创建它的对象。
I also wanted to do the same, but can't achieve it, its limitation of android os.
You HAVE TO RELEASE the connected camera object to be accessed by another.
The same problem is faced while accessing AudioRecord class, you just can't make an object of it until you release the first one.