I'm encountering an issue when attempting to open the rear camera in the maximum resolution with a 9:16 or any aspect ratio using HTML/JS. Despite setting the constraints, nothing appears on the preview. However, I can successfully grab an image from the stream. How is it possible that the preview remains black, and how can I detect this? Below is the HTML/JS code (tested on Chrome):

Javascript:

const video = document.querySelector('#video');

const constraints = {
    video: {
        height: { ideal: 2160 },
        width: { ideal: 4096 },
        facingMode: 'environment',
        aspectRatio: 9 / 16,
    },
};

navigator.mediaDevices.getUserMedia(constraints).then((stream) => {
    video.srcObject = stream;
}).catch((err) => {
    alert(err);
});

HTML: <video style="width: 90%" id="video" autoplay playsinline></video>

0

There are 0 best solutions below