Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pause and Resume not working as intented #736

Open
chatisk opened this issue Apr 3, 2023 · 2 comments
Open

Pause and Resume not working as intented #736

chatisk opened this issue Apr 3, 2023 · 2 comments

Comments

@chatisk
Copy link

chatisk commented Apr 3, 2023

Describe the bug
A clear and concise description of what the bug is.
Pause and Resume dont work as intented. Pause should stop scanning without closing the camera, and resume ,should start accepting scanning again. I notice that after pause, the state is set to PAUSED , and after the resume() method. I have to restart by using stop() first and then start() to be able to scan again.

To Reproduce
Steps to reproduce the behavior:

Expected behavior
A clear and concise description of what you expected to happen.
pause() expected behaviour would be stop PAUSE scanning. RESUME, should resume scanning

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: [e.g. iOS]
  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6]
  • OS: [e.g. iOS8.1]
  • Browser [e.g. stock browser, safari]
  • Version [e.g. 22]

Additional context
Add any other context about the problem here.

@tomasmalio
Copy link

tomasmalio commented Apr 16, 2023

I've the same problem. I can't stop reading with the camera.

I add in the success the html5QrcodeScanner.clear() but anything happened.

function onScanSuccess(decodedText, decodedResult) { showHint(decodedText); Html5QrcodeScanner.clear(); }

Anyone knows how to fix this?

@xjeffdbx
Copy link

I ran into a similar issue today after following a tutorial on YouTube. It turned out to be my own mistake.

I am playing around with this barcode scanner in Angular. Long story short, my callback success function didn't have a reference to my Html5QrcodeScanner object. No error was printed to the console, I found it after running my debugger.

The issue was was this line of code:
this.scanner.render(this.success, this.error);

which should have been:
this.scanner.render(this.success.bind(this), this.error.bind(this));

Alternatively, I could've used an arrow function:
https://stackoverflow.com/a/38245500

Here is my full class for reference:

import { AfterViewInit, Component } from '@angular/core';
import { Html5QrcodeScanner } from 'html5-qrcode';

@Component({
  selector: 'app-scanner',
  templateUrl: './scanner.page.html',
  styleUrls: ['./scanner.page.scss'],
})
export class ScannerPage implements AfterViewInit {
  scanner: Html5QrcodeScanner | undefined;

  ngAfterViewInit(): void {
    this.scanner = new Html5QrcodeScanner('reader', {
      qrbox: { width: 300, height: 150 },
      fps: 10
    }, false);

    // this.scanner.render(this.success, this.error);  // <<---------------------- old way
    this.scanner.render(this.success.bind(this), this.error.bind(this));
  }

  private success(decodedText: any, decodedResult: any) {
    console.log(`Code matched = ${decodedText}`, decodedResult);
    this.scanner!.pause(true);
  }

  private error(result: any) {}
}

Hope that helps someone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants