Home  >  Q&A  >  body text

html5 - How to turn off the local camera when using the getUserMedia method?

I used the navigator.mediaDevices.getUserMedia() method to open the local camera. I need to close it after taking the photo, but how to close it? Help...

女神的闺蜜爱上我女神的闺蜜爱上我2664 days ago1007

reply all(2)I'll reply

  • 学习ing

    学习ing2017-06-10 09:50:52

    stream.getTracks()[0].stop();

    stream is the instance in getUserMedia onSuccess callback

    Please refer to the documentation

    reply
    0
  • 女神的闺蜜爱上我

    女神的闺蜜爱上我2017-06-10 09:50:52

    navigator.mediaDevices.getUserMedia(constraints).then(function(stream) {
          var track = stream.getTracks()[0];  // if only one media track
            // ...
           track.stop();
    }).catch(function(err) {
      /* handle the error */
    });

    reply
    0
  • Cancelreply