How to stop the reader and turn off the camera
See original GitHub issueUsing: “@zxing/browser”: “0.0.5” Codebase: TypeScript project using lit-element
Hello,
I’m trying to implement this browser
version of the library in a small UI to scan PDF417 barcodes.
I am having a hard time understanding how to stop listening/scanning/reading and turning the camera off.
In the /library version I see I can call stop() on the reader, though it doesn’t appear to be available in this browser version for both types of VideoDevice decodes.
These pieces of code are lifted from the overall solution I’m trying to build.
In this first snippet I’m trying to decode once.
In this case, how can I stop the stream and turn off the camera - like a reset
async decodeOnce(codeReader: BrowserPDF417Reader, selectedDeviceId: string){
const videoElem = this.shadowRoot?.getElementById('video');
codeReader.decodeOnceFromVideoDevice(selectedDeviceId, videoElem).then((result) =>{
console.log(result);
}).catch( (reason) => {
console.log(reason);
});
}
In the DecodeContinously I can grab controls to stop the stream. I can now call this.controls.stop()
async decodeContinuously(codeReader: BrowserPDF417Reader, selectedDeviceId: string) {
const videoElem = this.shadowRoot?.getElementById('video');
this.controls = await codeReader.decodeFromVideoDevice(selectedDeviceId, videoElem, (result, error, controls)=>{
if (result){
console.log(result);
}
// TODO - handle exceptions
});
}
How to we properly turn off the camera and stop listening in the decodeOnce version?
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (5 by maintainers)
Top GitHub Comments
It was a bad design, hard to maintain and father of many bugs, it won’t come back. Instead we will create a simpler and elegant solution for this. When I have some free time, of course, or some kind soul sends a PR.
Althoug I never liked the AbortController, just
codeReader.reset()
would be nice if it is possible.