instascan
instascan copied to clipboard
BACK CAMERA DETECTION ISS
How to detect which camera is environment camera ? I'm using following code to detect back (environment) camera: -
public async ngOnInit() { console.log("Scanner"); try { const scanner = new Instascan.Scanner({ captureImage: true, video: document.getElementById("preview"), }); const cameraList = await Instascan.Camera.getCameras(); console.log("CAMERA LIST", cameraList); if (cameraList.length > 0) { let scanningAttempt = 0; const backCamera: Camera[] = this.getBackCamera(cameraList); await scanner.start(backCamera[0]); this.timerId = setInterval(() => { const scanResult: Scan = scanner.scan(); console.log("RESULT", scanResult); scanningAttempt++; if (scanResult) { this.onScan.emit(scanResult.content); scanner.stop(); clearInterval(this.timerId); }else { if (scanningAttempt === this.maxTimeoutCount) { scanner.stop(); clearInterval(this.timerId); this.onError.emit("NO_QR_CODE_FOUND"); } } }, 1000); }else { // console.error("No cameras found."); this.onError.emit("NO_ENV_CAMERA_FOUND"); } }catch (err) { console.log(err); this.onError.emit("NOT_ABLE_TO_PROCESS"); } } // BACK CAMERA FILTER private getBackCamera(cameras: Camera[]) { return cameras.filter((camera: Camera) => camera.name && camera.name.includes("back")); }
But "getBackCamera" fails when "camera.name" is null. is camera[1] is always back camera ?
I have the same issue. I tried it on a lot of different devices and i came to the conclusion, that camera[0] is back camera on iOS devices and camera[1] is front. On Android phones it's the opposite. My workaround was to implement a switch camera button
Thanks a lot buddy.
On Mon, 1 Apr 2019, 7:18 pm Mehmet Arziman <[email protected] wrote:
I have the same issue. I tried it on a lot of different devices and i came to the conclusion, that camera[0] is back camera on iOS devices and camera[1] is front. On Android phones it's the opposite. My workaround was to implement a switch camera button
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/schmich/instascan/issues/201#issuecomment-478586563, or mute the thread https://github.com/notifications/unsubscribe-auth/AX2ACJxVPq147Fh6f7-nB0-q_LMPB7VCks5vcg4zgaJpZM4ZjiZx .
Well, from my experience on the Samsung Galaxy S10 are both 0 and 1 front cameras.
I have the same issue. I tried it on a lot of different devices and i came to the conclusion, that camera[0] is back camera on iOS devices and camera[1] is front. On Android phones it's the opposite. My workaround was to implement a switch camera button
Hi kizilcali81, have you done implementing the switch camera? Really wanted to see how it goes
https://github.com/JoseCDB/instascan/tree/ios-rear-camera
This isn't working for me still I tried your version. Any ideas?