instascan
instascan copied to clipboard
Camera doesnt stop and doesnt restart.
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
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.
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-icon matSuffix><img src="./assets/images/QR_Scan_Icon.svg" (click)="Oninstascan(isclick)" /> i am not able to stop the camera or disable the scanner
this.scanner.stop();