ngx-scanner: Scanner failing to restart
Describe the bug
After successfully scanning, navigating away and then back to scanner page it fails to open on some devices. It throws the error NotReadableError NotReadableError: Could not start video source
.
And then
Error: Uncaught (in promise): Error: No scanning is running at the time.
Error: No scanning is running at the time.
at O.getScannerControls (https://cenyth.events/12-es2015.2dbdf0a52407038865e6.js:1:665378)
at t.scanStop (https://cenyth.events/12-es...
The only way to make it work again is to reload the page through the browser.
Expected behavior Scanner should restart successfully after reopening the scanner page and not require a refresh.
Smartphone (please complete the following information):
- Device: Amazon Kindle
- OS: Android 5.1.1
- Browser: Amazon Silk 8.9.27
- Version v3.1.3
Additional context Angular: 11.2.11 @zxing/browser: 0.0.7 @zxing/library: ^0.18.3 @zxing/ngx-scanner: ^3.1.3
As far as I know this didn’t happen a few versions ago with Angular 10
About this issue
- Original URL
- State: open
- Created 3 years ago
- Reactions: 2
- Comments: 19 (1 by maintainers)
So I was hoping 3.2.0 would fix the issue which is obviously not the case… Thanks for the information, I’ll see what I can do… PRs much appreciated!
Happening on my end as well. There’s a PR already in place, any chance to get a new build anytime soon?
I wrote a wrapper component to hold the zxing scanner and related services. It makes it possible to hook into the zxing scanner consistently, and I do this for most npm packages I’m using so I can change out packages by changing this one component instead of having to change everything that consumes the 3rd party package directly.
I’ve tried to trim this down as much as possible to give the relevant parts. This will feel like a lot (perhaps it is) to just have a way to cancel navigation while the camera is between the starting up step (initial load/enable=true) and started step (camerasFound event fires), but its what worked for me. Feel free to simplify or improve and share back.
The key is using the scanner service in your child/individual components that can navigate the router to a new route while the camera is starting. The example here,
some-other-component-consuming-scanner.component
has both the scanner and ana
tag, but you can have navigation points in other components depending on how specialized your app components get.scanner-camera.component.html
scanner-camera.component.ts
scanner-service.ts
some-other-component-consuming-scanner.component.html
some-other-component-consuming-scanner.component.ts
I have the same problem on Android. Is there any plans for the fix?
"@zxing/browser": "0.0.9"
"@zxing/library": "^0.18.6"
"@zxing/ngx-scanner": "3.2.0"
Reload helps.
<zxing-scanner [enable]="enable" [autostart]="true" [timeBetweenScans]="2000" [delayBetweenScanSuccess]="2000" (scanSuccess)="onScanSuccess($event)" (permissionResponse)="onPermissionResponse($event)" (hasDevices)="onHasDevices($event)" [formats]="['QR_CODE']"> </zxing-scanner>