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

时间:2018-05-10 22:58:34

标签: android camera android-camera android-camera2

我正在使用Android Camera2 API。我想知道什么时候适合:

  1. 最初显示 TakePicture 按钮(即相机已准备好捕捉 图片)。
  2. 再次显示此按钮(如果拍摄过程失败,当然还有完成时)因为我在点击它时隐藏它(捕捉图片)。
  3. 我在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会无限期地卡在aeStateif 中条件。

               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;
                }
    

1 个答案:

答案 0 :(得分:0)

我认为应该是这样

 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;
              }