Determining which camera is "macro" camera from mobile devices containing multiple cameras using getUserMedia

324 views
Skip to first unread message

Tom Landgrebe

unread,
Jan 30, 2021, 3:57:26 PM1/30/21
to Chromium-discuss
Good day,

We are trying to find a solution for selecting the correct camera (consistently) using "getUserMedia" when a mobile device has multiple rear cameras. In particular, we would like to select the "macro" camera, or camera for close-up imaging, as opposed to the wide angle camera. Reading the documentation, we cannot find a way to do it, and were hoping there may be a solution?

Currently we use the following routine to select a camera:

navigator.mediaDevices.enumerateDevices()
        .then(function (devices) {
          chosenId = devices.reverse().find(adevice => adevice.label.toLowerCase().includes("back"))?.deviceId
          navigator.mediaDevices.getUserMedia({ video: { facingMode: "environment", deviceId: chosenId, width: { ideal: 640 } }, audio: false })
            .then(function (stream) {
              videoRef.current.srcObject = stream
              const tracks = stream.getTracks()
              update()
            }, function (err: any): void {
              throw err
            })
        })
        .catch(function (err) {
          console.log(err.name + ": " + err.message);
        });

thank you very much
Tom
Reply all
Reply to author
Forward
0 new messages