schmich / instascan

HTML5 QR code scanner using your webcam
https://schmich.github.io/instascan/
MIT License
2.97k stars 864 forks source link

Camera doesnt stop and doesnt restart. #91

Open mgonekar opened 7 years ago

mgonekar commented 7 years ago

below is the function i am calling but the display stops not camera function closevideo(){ // want to stop camera as well scanner.stop(); }

and

     function restartcam() {
     Instascan.Camera.getCameras().then(function (cameras) {
            if (cameras.length > 0) {
              scanner.start(cameras[0]);
            } else {
              console.error('No cameras found.');
            }
          }).catch(function (e) {
            console.error(e);
          });

            let scanner = new Instascan.Scanner({ video: document.getElementById('preview'),refractoryPeriod: 1100 });
                  scanner.addListener('scan', function (content) {
                    console.log(content);

                    if(content.length > 0) {
                        findPrct(content); // want to call this function after scan
                    }

                  });
          }

Any help is much appreciated thanx

jjzlear commented 7 years ago

Try to define scanner out off restartcam(), because you will access the local instance of scanner in another function.

After this you can stop the camera.

dineshgunkala commented 6 years ago

Oninstascan(isclick) { debugger;
this.Instascan = require('instascan'); let scanner = new this.Instascan.Scanner({ video: document.getElementById("preview") });
if (this.isclick) {
this.ispreview = true; const that = this; scanner.addListener('scan', function (content: any, image: any) { if (content.length > 0) { that.AddBeacon.RabbitId = content; alert("Rabbit Id Scanned Successfully"); scanner.stop(); that.ispreview = false; that.isclick = true; } else { that.isclick = false; } }); this.Instascan.Camera.getCameras().then(function (cameras: any) { if (cameras.length > 0) { scanner.start(cameras[0]); that.isclick = false; } else { console.error('No cameras found.'); } }).catch(function (e: any) { console.error(e); }); } else { debugger; const that = this; this.ispreview = false; that.isclick = true; scanner.stop();
}

}

this is my code , for component and html code is below <input matInput placeholder="Rabbit ID" [(ngModel)]="AddBeacon.RabbitId" formControlName="RabbitId" maxlength="25" onkeypress='return event.charCode >= 48 && event.charCode <= 57 || event.key === "Backspace" ||event.key === "-"' name="RabbitId" required>

  </mat-form-field>

i am not able to stop the camera or disable the scanner

CyberFox404 commented 4 years ago

this.scanner.stop();