do you have any idea of why the following code doesn\'t work on Android/Chrome
?
It works well on Desktop/Chrome
.
According to MDN, navigator.getUserMedia()
is deprecated and isn't supported on Android/Chrome and some newer browser versions. Use navigator.mediaDevices.getUserMedia() instead. You can check browser compatibility below.
MDN Navigator.getUserMedia browser check
Here's a partial example I've used to access the camera for video streaming in a past project. The browser should ask the user for access on the device.
if(navigator.mediaDevices && navigator.mediaDevices.getUserMedia) {
navigator.mediaDevices.getUserMedia({ audio: false, video: cameraOrientation })
.then(function(stream) {
if ("srcObject" in video) {
video.srcObject = stream;
} else {
video.src = window.URL.createObjectURL(stream);
}
video.onloadedmetadata = function(e) {
video.play();
};
});
};