Reputation: 433
I'm using the Android Camera2 API. I would like to know when is the appropriate time to:
I tried takePicture.setVisibility(View.GONE)
in lockFocus()
and takePicture.setVisibility(View.VISIBLE)
in unlockFocus()
.
While this works most of the time, sometimes the button disappears and never appears again (when the process of taking a picture fails I guess) especially when clicking on it very quickly (as soon as it appears on the screen). No errors and no crash happen at this point.
The code is taken from googlesamples/android-Camera2Basic.
Update:
I tried takePicture.setVisibility(View.VISIBLE)
inside onCaptureSequenceCompleted
. The button does appear but the process of capturing a picture is not re-initiated when clicking on it (See this seven-second video). When this happens, the onCaptureFailed
is not called. However, it gets stuck indefinitely in STATE_WAITING_PRECAPTURE
or STATE_WAITING_NON_PRECAPTURE
because of aeState
which doesn't satisfy the if
condition.
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;
}
Upvotes: 1
Views: 1514
Reputation: 139
i think it should be like this,
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;
}
Upvotes: 1
Reputation: 4294
When it fails to take a picture, the CameraCaptureSession.CaptureCallback
's onCaptureCompleted
will not be called, so your takePicture.setVisibility(View.VISIBLE)
in unlockFocus()
which is called inside onCaptureCompleted
will not be called, then the button is disappeared.
You should handle the situation when the capture request fails. onCaptureFailed
and onCaptureSequenceCompleted
in CameraCaptureSession.CaptureCallback
will fulfill your requirement, and I prefer to use onCaptureSequenceCompleted
because it will be called no matter the capture request fail or succeed. However, you may also need consider about the abort situation, which is relevant to the callback method onCaptureSequenceAborted
.
See CameraCaptureSession.CaptureCallback for the full docs.
Upvotes: 0