Open mgonekar opened 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.
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
this.scanner.stop();
below is the function i am calling but the display stops not camera function closevideo(){ // want to stop camera as well scanner.stop(); }
and
Any help is much appreciated thanx