Skip to content

Commit bccd24b

Browse files
author
luowei
committed
Fix CameraCaptureSessionImpl.checkNotClosed exception when toggle aspectRatio
1 parent 27a307e commit bccd24b

File tree

1 file changed

+9
-8
lines changed
  • library/src/main/api21/com/google/android/cameraview

1 file changed

+9
-8
lines changed

library/src/main/api21/com/google/android/cameraview/Camera2.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public void onError(@NonNull CameraDevice camera, int error) {
9898

9999
@Override
100100
public void onConfigured(@NonNull CameraCaptureSession session) {
101-
if (mCamera == null) {
101+
if (!isCameraOpened()) {
102102
return;
103103
}
104104
mCaptureSession = session;
@@ -226,11 +226,9 @@ boolean start() {
226226

227227
@Override
228228
void stop() {
229-
if (mCaptureSession != null) {
230-
mCaptureSession.close();
231-
mCaptureSession = null;
232-
}
233-
if (mCamera != null) {
229+
closeCaptureSession();
230+
231+
if (isCameraOpened()) {
234232
mCamera.close();
235233
mCamera = null;
236234
}
@@ -285,12 +283,15 @@ boolean setAspectRatio(AspectRatio ratio) {
285283

286284
mAspectRatio = ratio;
287285
prepareImageReader();
286+
closeCaptureSession();
287+
return true;
288+
}
289+
290+
private void closeCaptureSession() {
288291
if (mCaptureSession != null) {
289292
mCaptureSession.close();
290293
mCaptureSession = null;
291-
startCaptureSession();
292294
}
293-
return true;
294295
}
295296

296297
@Override

0 commit comments

Comments
 (0)