js asks the browser for device authorization such as camera

Turn on camera

Note: Turning on the camera requires the browser website to be set to the inquiry state. If it is in the rejection state, it cannot be turned on.
Insert image description here

Calling method navigator.mediaDevices.getUserMedia(

const constrains = {
    video: true,
    audio: true
  }
  	navigator.mediaDevices.getUserMedia(constrains)
    .then(stream => {
      console.log('得到stream的类型是MediaStream')
    }).catch(err => {
      console.log(err, 拒绝)
    })

Turn off camera

var mediaStreamTrack =  stream.getTracks()[0];
mediaStreamTrack.stop();

Guess you like

Origin blog.csdn.net/weixin_42215897/article/details/128146710