使用Android Camera2,应用无限期陷入STATE_WAITING_PRECAPTURE或STATE_WAITING_NON_PRECAPTURE

休言女子非英物,夜夜龙泉壁上鸣。这篇文章主要讲述使用Android Camera2,应用无限期陷入STATE_WAITING_PRECAPTURE或STATE_WAITING_NON_PRECAPTURE相关的知识,希望能为你提供帮助。
我正在使用Android Camera2 API。我想知道什么时候适合:

  1. 最初显示TakePicture按钮(即相机已准备好拍摄照片)。
  2. 再次显示此按钮(如果拍摄过程失败,当然还有完成时),因为我在点击它时隐藏它(捕捉图片)。
我在takePicture.setVisibility(View.GONE)lockFocus()takePicture.setVisibility(View.VISIBLE)尝试过unlockFocus()。虽然这在大多数时间都有效,但有时按钮会消失并且再也不会出现(当我拍摄照片的过程失败时),特别是当它非常快速地点击它时(一旦它出现在屏幕上)。此时没有错误也没有发生崩溃。
代码取自googlesamples/android-Camera2Basic。
更新:
我在takePicture.setVisibility(View.VISIBLE)里面尝试过onCaptureSequenceCompleted。按钮确实出现,但点击它时不会重新启动捕获图片的过程(请参阅this seven-second video)。发生这种情况时,不会调用onCaptureFailed。然而,由于STATE_WAITING_PRECAPTURE不满足STATE_WAITING_NON_PRECAPTURE条件,它无限期地卡在aeStateor if中。
case STATE_WAITING_PRECAPTURE: { // CONTROL_AE_STATE can be null on some devices Integer aeState = result.get(CaptureResult.CONTROL_AE_STATE); if (aeState == null || aeState == CaptureResult.CONTROL_AE_STATE_PRECAPTURE || aeState == CaptureRequest.CONTROL_AE_STATE_FLASH_REQUIRED) { mState = STATE_WAITING_NON_PRECAPTURE; } break; } case STATE_WAITING_NON_PRECAPTURE: { // CONTROL_AE_STATE can be null on some devices Integer aeState = result.get(CaptureResult.CONTROL_AE_STATE); if (aeState == null || aeState != CaptureResult.CONTROL_AE_STATE_PRECAPTURE) { mState = STATE_PICTURE_TAKEN; captureStillPicture(); } break; }

答案当它没有拍照时,CameraCaptureSession.CaptureCallbackonCaptureCompleted将不会被调用,所以在takePicture.setVisibility(View.VISIBLE)中调用unlockFocus()onCaptureCompleted将不被调用,然后按钮消失。
您应该在捕获请求失败时处理这种情况。 onCaptureFailed中的onCaptureSequenceCompletedCameraCaptureSession.CaptureCallback将满足您的要求,我更喜欢使用onCaptureSequenceCompleted,因为无论捕获请求失败还是成功,都会调用它。但是,您可能还需要考虑中止情况,该情况与回调方法onCaptureSequenceAborted相关。
有关完整文档,请参阅CameraCaptureSession.CaptureCallback。
另一答案【使用Android Camera2,应用无限期陷入STATE_WAITING_PRECAPTURE或STATE_WAITING_NON_PRECAPTURE】我认为它应该是这样的,
case STATE_WAITING_PRECAPTURE: { JQLog.d(TAG, "STATE_WAITING_PRECAPTURE"); // CONTROL_AE_STATE can be null on some devices Integer aeState = result.get(CaptureResult.CONTROL_AE_STATE); if (aeState == null || aeState == CaptureResult.CONTROL_AE_STATE_PRECAPTURE || aeState == CaptureRequest.CONTROL_AE_STATE_FLASH_REQUIRED || aeState == CaptureResult.CONTROL_AE_STATE_CONVERGED) { state = STATE_WAITING_NON_PRECAPTURE; } break; }


    推荐阅读