Android的 - 无法连接到相机 [英] Android - Fail to connect to camera
本文介绍了Android的 - 无法连接到相机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我采用的是Android APIDemo样品code。
I'm using the Android APIDemo sample code.
当我运行摄像机preVIEW例如,在一开始是给我一个错误一>。
When I run the CameraPreview example, at first it was giving me an error.
我跟踪一个下来的样品工作一段时间。
现在,它不再起作用。它说
I traced that one down and the sample was working for a while.
Now, it no longer works. It says
ERROR/AndroidRuntime(2949): java.lang.RuntimeException: Fail to connect to camera service
有什么可以引起的?它发生在 camera.open()
之称。
谢谢,
T恤
推荐答案
请务必正确释放所有的获得性摄像头资源:
Be sure to properly release all the aquired camera resources:
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
if (mCam != null) {
mCam.stopPreview();
mCam.setPreviewCallback(null);
mCam.release();
mCam = null;
}
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
if (mCam == null) {
mCam = Camera.open();
try {
mCam.setPreviewDisplay(holder);
// TODO test how much setPreviewCallbackWithBuffer is faster
mCam.setPreviewCallback(this);
} catch (IOException e) {
mCam.release();
mCam = null;
}
}
}
这篇关于Android的 - 无法连接到相机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文