instascan icon indicating copy to clipboard operation
instascan copied to clipboard

BACK CAMERA DETECTION ISS

Open sauravgaursmith opened this issue 5 years ago • 6 comments

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 ?

sauravgaursmith avatar Dec 28 '18 07:12 sauravgaursmith

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

kizilcali81 avatar Apr 01 '19 13:04 kizilcali81

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 .

sauravgaursmith avatar Apr 01 '19 14:04 sauravgaursmith

Well, from my experience on the Samsung Galaxy S10 are both 0 and 1 front cameras.

xdibda avatar Jul 01 '19 13:07 xdibda

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

akbarnoor94 avatar Sep 28 '19 16:09 akbarnoor94

https://github.com/JoseCDB/instascan/tree/ios-rear-camera

guidomgs avatar May 08 '20 01:05 guidomgs

This isn't working for me still I tried your version. Any ideas?

AplAddict avatar May 23 '23 20:05 AplAddict