FrontMode in MediaDevices.getUserMedia doesn't seem to work in recent versions of Android Chrome (v53)

I have a function that allows the user to select a camera and show the captured video on the page [like this] . My code works before Android Google Chrome version 52, but I don’t know why it is now broken.

First, I check which devices I can use.

navigator.mediaDevices.enumerateDevices()
.then(function(devices) {
  devices.forEach(function(device) {
    console.log(device.kind + ": " + device.label +
                " id = " + device.deviceId);
  });
})
.catch(function(err) {
  console.log(err.name + ": " + err.message);
});

and it brings back two cameras (one front, one back), as I expect.

videoinput: camera 1, front ID = ef5f41259c805a533261c2d91c274fdbfa8a6c8d629231cb484845032f90e61a camera: 19 video input: camera 0, back side id = 81448a117b2569ba9af905d01384b3217fbfbd

Then I follow the sample code , and below what I use:

<video id="video" autoplay></video>
<script>
    var p = navigator.mediaDevices.getUserMedia({ video: {facingMode: "environment", width: 480, height: 800} });

    p.then(function(mediaStream) {
      var video = document.querySelector('video');
      video.src = window.URL.createObjectURL(mediaStream);
      video.onloadedmetadata = function(e) {
          // Do something with the video here.
      };
    });

    p.catch(function(err) { console.log(err.name); }); // always check for errors at the end.
</script>

facingMode: "environment" facingMode: {exact:"environment"}, . Google?

+4

Source: https://habr.com/ru/post/1657583/


All Articles