Showing
1 changed file
with
19 additions
and
9 deletions
| @@ -28,7 +28,6 @@ import android.view.WindowManager | @@ -28,7 +28,6 @@ import android.view.WindowManager | ||
| 28 | import android.content.Context | 28 | import android.content.Context |
| 29 | import android.os.Build | 29 | import android.os.Build |
| 30 | 30 | ||
| 31 | - | ||
| 32 | class MobileScanner( | 31 | class MobileScanner( |
| 33 | private val activity: Activity, | 32 | private val activity: Activity, |
| 34 | private val textureRegistry: TextureRegistry, | 33 | private val textureRegistry: TextureRegistry, |
| @@ -213,6 +212,7 @@ class MobileScanner( | @@ -213,6 +212,7 @@ class MobileScanner( | ||
| 213 | torchStateCallback: TorchStateCallback, | 212 | torchStateCallback: TorchStateCallback, |
| 214 | zoomScaleStateCallback: ZoomScaleStateCallback, | 213 | zoomScaleStateCallback: ZoomScaleStateCallback, |
| 215 | mobileScannerStartedCallback: MobileScannerStartedCallback, | 214 | mobileScannerStartedCallback: MobileScannerStartedCallback, |
| 215 | + mobileScannerErrorCallback: (exception: Exception) -> Unit, | ||
| 216 | detectionTimeout: Long, | 216 | detectionTimeout: Long, |
| 217 | cameraResolution: Size? | 217 | cameraResolution: Size? |
| 218 | ) { | 218 | ) { |
| @@ -221,7 +221,9 @@ class MobileScanner( | @@ -221,7 +221,9 @@ class MobileScanner( | ||
| 221 | this.returnImage = returnImage | 221 | this.returnImage = returnImage |
| 222 | 222 | ||
| 223 | if (camera?.cameraInfo != null && preview != null && textureEntry != null) { | 223 | if (camera?.cameraInfo != null && preview != null && textureEntry != null) { |
| 224 | - throw AlreadyStarted() | 224 | + mobileScannerErrorCallback(AlreadyStarted()) |
| 225 | + | ||
| 226 | + return | ||
| 225 | } | 227 | } |
| 226 | 228 | ||
| 227 | scanner = if (barcodeScannerOptions != null) { | 229 | scanner = if (barcodeScannerOptions != null) { |
| @@ -237,7 +239,9 @@ class MobileScanner( | @@ -237,7 +239,9 @@ class MobileScanner( | ||
| 237 | cameraProvider = cameraProviderFuture.get() | 239 | cameraProvider = cameraProviderFuture.get() |
| 238 | 240 | ||
| 239 | if (cameraProvider == null) { | 241 | if (cameraProvider == null) { |
| 240 | - throw CameraError() | 242 | + mobileScannerErrorCallback(CameraError()) |
| 243 | + | ||
| 244 | + return@addListener | ||
| 241 | } | 245 | } |
| 242 | 246 | ||
| 243 | cameraProvider?.unbindAll() | 247 | cameraProvider?.unbindAll() |
| @@ -292,12 +296,18 @@ class MobileScanner( | @@ -292,12 +296,18 @@ class MobileScanner( | ||
| 292 | 296 | ||
| 293 | val analysis = analysisBuilder.build().apply { setAnalyzer(executor, captureOutput) } | 297 | val analysis = analysisBuilder.build().apply { setAnalyzer(executor, captureOutput) } |
| 294 | 298 | ||
| 295 | - camera = cameraProvider!!.bindToLifecycle( | ||
| 296 | - activity as LifecycleOwner, | ||
| 297 | - cameraPosition, | ||
| 298 | - preview, | ||
| 299 | - analysis | ||
| 300 | - ) | 299 | + try { |
| 300 | + camera = cameraProvider?.bindToLifecycle( | ||
| 301 | + activity as LifecycleOwner, | ||
| 302 | + cameraPosition, | ||
| 303 | + preview, | ||
| 304 | + analysis | ||
| 305 | + ) | ||
| 306 | + } catch(exception: Exception) { | ||
| 307 | + mobileScannerErrorCallback(NoCamera()) | ||
| 308 | + | ||
| 309 | + return@addListener | ||
| 310 | + } | ||
| 301 | 311 | ||
| 302 | camera?.let { | 312 | camera?.let { |
| 303 | // Register the torch listener | 313 | // Register the torch listener |
-
Please register or login to post a comment