Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Prev Previous commit
Next Next commit
Makde corrections
  • Loading branch information
camsim99 committed May 25, 2022
commit ad487334e5ef9ea37470144386d343e24af64df9
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ public void onDisconnected(@NonNull CameraDevice cameraDevice) {
@Override
public void onError(@NonNull CameraDevice cameraDevice, int errorCode) {
Log.i(TAG, "open | onError");

close();

String errorDescription;
Expand Down Expand Up @@ -394,7 +394,7 @@ private void createCaptureSession(
int templateType, Runnable onSuccessCallback, Surface... surfaces)
throws CameraAccessException {
// Close any existing capture session.
closeCaptureSession();
captureSession = null;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is still necessary.

Creating a new capture session with CameraDevice#createCaptureSession will close any existing capture session automatically, and call the older session listener's StateCallback#onClosed callback.

This plugin is using https://developer.android.com/reference/android/hardware/camera2/CameraDevice#createCaptureRequest(int) instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CameraDevice#createCaptureSession is getting called further down in the method, see here. As you'll see, for API 27 and below, the deprecated version of CameraDevice#createCaptureSession is actually used (see here), but it too takes care of closing the old capture session because both ultimately call this method to close the session.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. Thank you


// Create a new capture builder.
previewRequestBuilder = cameraDevice.createCaptureRequest(templateType);
Expand Down Expand Up @@ -1181,12 +1181,15 @@ private void closeCaptureSession() {

public void close() {
Log.i(TAG, "close");
captureSession = null;

if (cameraDevice != null) {
cameraDevice.close();
cameraDevice = null;
captureSession = null;
} else {
closeCaptureSession();
}

if (pictureImageReader != null) {
pictureImageReader.close();
pictureImageReader = null;
Expand Down