schmich / instascan

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

Select camera to scan #238

Open arnaubosch opened 4 years ago

arnaubosch commented 4 years ago

I have a website where I scan QR CODES using instascan.

I access to the website using my mobiIe phone thas has 4 back cameras (HUAWEI P30 PRO).

I have implmented a for each that selects the first 'back' camera:

if (cameras.length > 0) { var selectedCam = cameras[0]; $.each(cameras, (i, c) => { if (c.name.indexOf('back') != -1) { selectedCam = c; return false; } }); scanner.start(selectedCam); }

But with that selectedCamera the vision is so fuzzy and I can't scan the QR. If I select by default the 2nd camera of the array by doing scanner.start(cameras[2]); the vision is perfect and I can scan all the QR.

Anyone knows a generic way to pick the correct back camera? I mean my webapp is going to be used by so many users that will have differents mobile phones so different numbers of cameras.

arnaubosch commented 4 years ago

@schmich