library
library copied to clipboard
Starting camera after resetting throws an error when using Firefox mobile
Describe the bug
Starting the scanner, after resetting it and using another camera, causes Firefox mobile to throw an error, that the video could not be started. No other browser I've tested throws such an error. Adding a 2 second delay after reset seems to make it work every time.
To Reproduce Steps to reproduce the behavior:
- Start the camera stream.
- Reset the qr scanner
- Start it again in the same function, programatically.
Expected behavior Camera feed appears in the video element, just like in Chrome.
Smartphone (please complete the following information):
- Device: Samsung Galaxy S7, Samsung Galaxy Note 9
- OS: Android 8, 10
- Browser: Firefox mobile
- Version: newest at the time of writing
Additional context Adding a 2 second delay before restarting the qr scanner seems to make it work.
Here's a snippet, basically I keep the available cameras in a variable, and switch between them with a single button:
$("#next-cam-button").on("click", function () {
if (canChangeCam){
canChangeCam = false;
codeReader.reset();
selectedDeviceId = getNextCamera();
showLoader();
if (isFirefox && isAndroid){ // firefox bugs out otherwise?
delay(2000).then( () => startScan());
}
else{ startScan(); }
}
})
function getNextCamera(){
currentCamIndex++;
if (currentCamIndex >= availableCameras.length){
currentCamIndex = 0;
}
return availableCameras[currentCamIndex].deviceId;
}
function startScan(){
codeReader.decodeFromVideoDevice(selectedDeviceId, 'camera-stream', (result, err) => {
if (result) {
console.log(result)
lastScannedString = result.text;
}
if (err && !(err instanceof ZXing.NotFoundException)) {
console.error("Error: " +err);
}
})
console.log(`Started continous decode from camera with id ${selectedDeviceId}`)
}
Stale issue message