fix: Fix Session has been closed; further changes are illegal error by using tryStopRepeating() (#2568)

* feat: Allow focus calls to be cancelable

* Cancelable

* fix: Use `tryStopRepeating`
This commit is contained in:
Marc Rousavy 2024-02-15 17:34:55 +01:00 committed by GitHub
parent 4168d8f752
commit 129e21f14e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 1 deletions

View File

@ -19,6 +19,7 @@ import com.mrousavy.camera.extensions.isValid
import com.mrousavy.camera.extensions.openCamera import com.mrousavy.camera.extensions.openCamera
import com.mrousavy.camera.extensions.precapture import com.mrousavy.camera.extensions.precapture
import com.mrousavy.camera.extensions.tryAbortCaptures import com.mrousavy.camera.extensions.tryAbortCaptures
import com.mrousavy.camera.extensions.tryStopRepeating
import com.mrousavy.camera.types.Flash import com.mrousavy.camera.types.Flash
import com.mrousavy.camera.types.Orientation import com.mrousavy.camera.types.Orientation
import com.mrousavy.camera.types.QualityPrioritization import com.mrousavy.camera.types.QualityPrioritization
@ -280,8 +281,8 @@ class PersistentCameraCaptureSession(private val cameraManager: CameraManager, p
val builder = repeatingRequest.createCaptureRequest(device, details, repeatingOutputs) val builder = repeatingRequest.createCaptureRequest(device, details, repeatingOutputs)
session.setRepeatingRequest(builder.build(), null, null) session.setRepeatingRequest(builder.build(), null, null)
} else { } else {
session.stopRepeating()
Log.d(TAG, "Stopping repeating request...") Log.d(TAG, "Stopping repeating request...")
session.tryStopRepeating()
} }
Log.d(TAG, "Configure() done! isActive: $isActive, ID: $cameraId, device: $device, session: $session") Log.d(TAG, "Configure() done! isActive: $isActive, ID: $cameraId, device: $device, session: $session")
} catch (e: CameraAccessException) { } catch (e: CameraAccessException) {

View File

@ -0,0 +1,9 @@
package com.mrousavy.camera.extensions
import android.hardware.camera2.CameraCaptureSession
fun CameraCaptureSession.tryStopRepeating() {
try {
stopRepeating()
} catch (_: Throwable) {}
}