我达到了我称之为createCaptureSession()
的程度,但随后onConfigureFailed()
被调用,我不知道问题是什么或如何找到它.
这是我的来源:
SurfaceVIEw mSurfaceVIEw;@OverrIDeprotected voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Log.d(TAG,"onCreate() start"); setContentVIEw(R.layout.activity_main); mSurfaceVIEw = (SurfaceVIEw) findVIEwByID(R.ID.surfaceVIEw);}protected voID onResume() { super.onResume(); Log.d(TAG,"onResume() start"); initCamera();}private voID initCamera() { Log.d(TAG,"initCamera() start"); CameraManager cameraManager = (CameraManager) getSystemService(Context.CAMERA_SERVICE); Log.d(TAG,"acquired cameraManager: " + cameraManager); String[] cameraIDList; try { cameraIDList = cameraManager.getCameraIDList(); } catch (CameraAccessException e) { Log.e(TAG,"Couldn't get camera List",e); return; } Log.d(TAG,"acquired cameraIDList: length: " + cameraIDList.length); if (cameraIDList.length == 0) { Log.w(TAG,"Couldn't detect a camera"); return; } String camera0ID = cameraIDList[0]; Log.d(TAG,"chosen camera: " + camera0ID); try { cameraManager.openCamera(camera0ID,deviceCallback,null); } catch (CameraAccessException e) { Log.e(TAG,"Couldn't open camera",e); } Log.d(TAG,"called cameraManager.openCamera()");}CameraDevice.StateCallback deviceCallback = new CameraDevice.StateCallback() { @OverrIDe public voID onopened(CameraDevice camera) { Log.d(TAG,"deviceCallback.onopened() start"); Surface surface = mSurfaceVIEw.getHolder().getSurface(); Log.d(TAG,"surface: " + surface); List<Surface> surfaceList = Collections.singletonList(surface); try { camera.createCaptureSession(surfaceList,sessionCallback,null); } catch (CameraAccessException e) { Log.e(TAG,"Couldn't create capture session for camera: " + camera.getID(),e); return; } } @OverrIDe public voID ondisconnected(CameraDevice camera) { Log.d(TAG,"deviceCallback.ondisconnected() start"); } @OverrIDe public voID onError(CameraDevice camera,int error) { Log.d(TAG,"deviceCallback.onError() start"); }};CameraCaptureSession.StateCallback sessionCallback = new CameraCaptureSession.StateCallback() { @OverrIDe public voID onConfigured(CameraCaptureSession session) { Log.i(TAG,"capture session configured: " + session); } @OverrIDe public voID onConfigureFailed(CameraCaptureSession session) { Log.e(TAG,"capture session configure Failed: " + session); }};
输出是:
...﹕ onCreate() start...﹕ onResume() start...﹕ initCamera() start...﹕ acquired cameraManager: androID.harDWare.camera2.CameraManager@5d68786...﹕ acquired cameraIDList: length: 2...﹕ chosen camera: 0...﹕ called cameraManager.openCamera()...﹕ deviceCallback.onopened() start...﹕ surface: Surface(name=null)/@0x52c91e3...﹕ capture session configure Failed: androID.harDWare.camera2.impl.CameraCaptureSessionImpl@1a8c7a99
以下是我的AndroIDManifest.xml:
<uses-permission androID:name="androID.permission.CAMERA" /><uses-feature androID:name="androID.harDWare.camera" /><uses-feature androID:name="androID.harDWare.camera2" />解决方法 你应该设置预览的大小
mSurfaceVIEw.getHolder().setFixedSize(prevIEwSize.getWIDth(),prevIEwSize.getHeight());总结
以上是内存溢出为你收集整理的使用android camera2 API显示摄像头源全部内容,希望文章能够帮你解决使用android camera2 API显示摄像头源所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)