Skip to content
This repository has been archived by the owner on Dec 29, 2022. It is now read-only.

fix crash (Issue #11) #136

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public void onError(@NonNull CameraDevice camera, int error) {

@Override
public void onConfigured(@NonNull CameraCaptureSession session) {
if (mCamera == null) {
if (!isCameraOpened()) {
return;
}
mCaptureSession = session;
Expand Down Expand Up @@ -202,7 +202,7 @@ public void onImageAvailable(ImageReader reader) {
mPreview.setCallback(new PreviewImpl.Callback() {
@Override
public void onSurfaceChanged() {
startCaptureSession();
restartCaptureSession();
}
});
}
Expand All @@ -224,7 +224,7 @@ void stop() {
mCaptureSession.close();
mCaptureSession = null;
}
if (mCamera != null) {
if (isCameraOpened()) {
mCamera.close();
mCamera = null;
}
Expand Down Expand Up @@ -269,12 +269,16 @@ boolean setAspectRatio(AspectRatio ratio) {
return false;
}
mAspectRatio = ratio;
restartCaptureSession();
return true;
}

private void restartCaptureSession() {
if (mCaptureSession != null) {
mCaptureSession.close();
mCaptureSession = null;
startCaptureSession();
}
return true;
}

@Override
Expand Down