question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to stop the reader and turn off the camera

See original GitHub issue

Using: “@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:closed
  • Created 3 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
odahcamcommented, Feb 1, 2021

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.

1reaction
thisconnectcommented, Feb 1, 2021

Althoug I never liked the AbortController, just codeReader.reset() would be nice if it is possible.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Turn Off the Live Text Feature on Your iPhone or Mac
If the Live Text feature on you iPhone is actively annoying you, here's how to disable it.
Read more >
How to Disable Live Text on iPhone and iPad - MacRumors
1. Launch the Settings app. 2. Tap General. 3. Tap Language & Region.
Read more >
Want to Turn Off the Pesky Live Text on an iPhone, iPad, or ...
How to Disable Live Text on Your iPhone or iPad · Go to Settings > Camera. · Toggle the switch off beside Show...
Read more >
Turn TalkBack on or off - Android Accessibility Help
The TalkBack screen reader gives you spoken feedback and notifications. Contents Option 1: With the volume key shortcut Option 2: With Google Assistant....
Read more >
How to turn off Night Mode on iPhone camera and keep it off - P
To turn Night Mode off for an individual photo, you just need to tap on the Night Mode icon at the top of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found