Skip to content Skip to sidebar Skip to footer

GetUserMedia() - Selecting Rear Camera On Mobile

This is my question. I'm making a little app that uses JS-OCR to take a photo and detect a word. It works well, but in I only can user the front camera. My idea is to use only the

Solution 1:

navigator.getUserMedia is long deprecated. Use navigator.mediaDevices.getUserMedia now.

To get the rear camera, you can use the MediaConstraint:video:facingMode property. Available values are 'user' (front camera), and 'environment' (back camera).

navigator.mediaDevices.getUserMedia({
  audio: false,
  video: {
    facingMode: 'environment'
  }
})
  .then(stream => vid.srcObject = stream)
  .catch(console.error);
<video muted autoplay id="vid"></video>

Or as a fiddle since null origin StackSnippet's iframe may block the request to gUM.


Post a Comment for "GetUserMedia() - Selecting Rear Camera On Mobile"