Me and my friend are building an app that requires camera access and we're having some issue with getting the camera working with iOS (we're using iOS13):
Safari freeze right after getting the camera content, chrome and edge doesn't acquire camera access at all. Our code is as follow:
let windowWidth=window.innerWidth;
let windowHeight=window.innerHeight;
function isMobile() {
const isAndroid = /Android/i.test(navigator.userAgent);
const isiOS = /iPhone|iPad|iPod/i.test(navigator.userAgent);
return isAndroid || isiOS;
}
async function setupCamera() {
video = document.getElementById('video');
console.log("a")
video.setAttribute('autoplay', '');
video.setAttribute('muted', '');
video.setAttribute('playsinline', '');
const stream = await navigator.mediaDevices.getUserMedia({
'audio': false,
'video': {
facingMode: 'user',
width: mobile ? undefined : windowWidth,
height: mobile ? undefined : windowHeight
},
});
console.log("b")
video.srcObject = stream;
return new Promise((resolve) => {
video.onloadedmetadata = () => {
resolve(video);
};
});
}
According to the console, 'a' always gets printed but never 'b'. Any clue on what's wrong will be greatly appreciated!