Showing
1 changed file
with
7 additions
and
1 deletions
| @@ -208,6 +208,10 @@ class MobileScanner( | @@ -208,6 +208,10 @@ class MobileScanner( | ||
| 208 | 208 | ||
| 209 | // Preview | 209 | // Preview |
| 210 | val surfaceProvider = Preview.SurfaceProvider { request -> | 210 | val surfaceProvider = Preview.SurfaceProvider { request -> |
| 211 | + if (isStopped()) { | ||
| 212 | + return@SurfaceProvider | ||
| 213 | + } | ||
| 214 | + | ||
| 211 | val texture = textureEntry!!.surfaceTexture() | 215 | val texture = textureEntry!!.surfaceTexture() |
| 212 | texture.setDefaultBufferSize( | 216 | texture.setDefaultBufferSize( |
| 213 | request.resolution.width, | 217 | request.resolution.width, |
| @@ -270,7 +274,7 @@ class MobileScanner( | @@ -270,7 +274,7 @@ class MobileScanner( | ||
| 270 | * Stop barcode scanning. | 274 | * Stop barcode scanning. |
| 271 | */ | 275 | */ |
| 272 | fun stop() { | 276 | fun stop() { |
| 273 | - if (camera == null && preview == null) { | 277 | + if (isStopped()) { |
| 274 | throw AlreadyStopped() | 278 | throw AlreadyStopped() |
| 275 | } | 279 | } |
| 276 | 280 | ||
| @@ -285,6 +289,8 @@ class MobileScanner( | @@ -285,6 +289,8 @@ class MobileScanner( | ||
| 285 | cameraProvider = null | 289 | cameraProvider = null |
| 286 | } | 290 | } |
| 287 | 291 | ||
| 292 | + private fun isStopped() = camera == null && preview == null | ||
| 293 | + | ||
| 288 | /** | 294 | /** |
| 289 | * Toggles the flash light on or off. | 295 | * Toggles the flash light on or off. |
| 290 | */ | 296 | */ |
-
Please register or login to post a comment