Showing
3 changed files
with
24 additions
and
0 deletions
| @@ -129,6 +129,11 @@ abstract class BarcodeReader { | @@ -129,6 +129,11 @@ abstract class BarcodeReader { | ||
| 129 | throw UnimplementedError('start() has not been implemented.'); | 129 | throw UnimplementedError('start() has not been implemented.'); |
| 130 | } | 130 | } |
| 131 | 131 | ||
| 132 | + /// Pause the barcode reader. | ||
| 133 | + Future<void> pause() { | ||
| 134 | + throw UnimplementedError('pause() has not been implemented.'); | ||
| 135 | + } | ||
| 136 | + | ||
| 132 | /// Stop the barcode reader and dispose of the video stream. | 137 | /// Stop the barcode reader and dispose of the video stream. |
| 133 | Future<void> stop() { | 138 | Future<void> stop() { |
| 134 | throw UnimplementedError('stop() has not been implemented.'); | 139 | throw UnimplementedError('stop() has not been implemented.'); |
| 1 | import 'dart:async'; | 1 | import 'dart:async'; |
| 2 | +import 'dart:developer'; | ||
| 3 | +import 'dart:html'; | ||
| 2 | import 'dart:js_interop'; | 4 | import 'dart:js_interop'; |
| 3 | import 'dart:ui_web' as ui_web; | 5 | import 'dart:ui_web' as ui_web; |
| 4 | 6 | ||
| @@ -235,6 +237,11 @@ class MobileScannerWeb extends MobileScannerPlatform { | @@ -235,6 +237,11 @@ class MobileScannerWeb extends MobileScannerPlatform { | ||
| 235 | throw PermissionRequestPendingException(); | 237 | throw PermissionRequestPendingException(); |
| 236 | } | 238 | } |
| 237 | 239 | ||
| 240 | + // If the previous state is a pause, reset scanner. | ||
| 241 | + if (_barcodesSubscription != null && _barcodesSubscription!.isPaused) { | ||
| 242 | + await stop(); | ||
| 243 | + } | ||
| 244 | + | ||
| 238 | await _barcodeReader.maybeLoadLibrary( | 245 | await _barcodeReader.maybeLoadLibrary( |
| 239 | alternateScriptUrl: _alternateScriptUrl, | 246 | alternateScriptUrl: _alternateScriptUrl, |
| 240 | ); | 247 | ); |
| @@ -336,6 +343,13 @@ class MobileScannerWeb extends MobileScannerPlatform { | @@ -336,6 +343,13 @@ class MobileScannerWeb extends MobileScannerPlatform { | ||
| 336 | } | 343 | } |
| 337 | } | 344 | } |
| 338 | 345 | ||
| 346 | + | ||
| 347 | + @override | ||
| 348 | + Future<void> pause() async { | ||
| 349 | + _barcodesSubscription?.pause(); | ||
| 350 | + await _barcodeReader.pause(); | ||
| 351 | + } | ||
| 352 | + | ||
| 339 | @override | 353 | @override |
| 340 | Future<void> stop() async { | 354 | Future<void> stop() async { |
| 341 | if (_barcodesController.isClosed) { | 355 | if (_barcodesController.isClosed) { |
| @@ -192,6 +192,11 @@ final class ZXingBarcodeReader extends BarcodeReader { | @@ -192,6 +192,11 @@ final class ZXingBarcodeReader extends BarcodeReader { | ||
| 192 | } | 192 | } |
| 193 | 193 | ||
| 194 | @override | 194 | @override |
| 195 | + Future<void> pause() async { | ||
| 196 | + _reader?.videoElement?.pause(); | ||
| 197 | + } | ||
| 198 | + | ||
| 199 | + @override | ||
| 195 | Future<void> stop() async { | 200 | Future<void> stop() async { |
| 196 | _onMediaTrackSettingsChanged = null; | 201 | _onMediaTrackSettingsChanged = null; |
| 197 | _reader?.stopContinuousDecode.callAsFunction(_reader as JSAny?); | 202 | _reader?.stopContinuousDecode.callAsFunction(_reader as JSAny?); |
-
Please register or login to post a comment