How to use back camera instead of the front camera?

后端 未结 2 887
甜味超标
甜味超标 2020-12-21 09:23

I have a QR scanning camera, but when I open my website on a cell phone, the face camera turns on in my website. I want to use the back camera.

function set         


        
相关标签:
2条回答
  • 2020-12-21 09:38

    If you want to force the device to use front camera you can add facingMode in constraints:

    var constraints = { 
      audio: true,
      video: {
        facingMode: 'environment'
    };
    

    or use exact:

    facingMode: { exact: 'environment' }
    
    0 讨论(0)
  • 2020-12-21 09:54

    You can use MediaStreamTrack.getSources(callback) to get all media sources and their id's. With other properties you can filter to check is it audio video or filter by name. Once you know id of media source you want to show, use it to attach it to video tag.

    This is good example:
    https://simpl.info/getusermedia/sources/
    https://github.com/samdutton/simpl/blob/master/getusermedia/sources/js/main.js

    0 讨论(0)
提交回复
热议问题