1

I am using react-webcam to capture photos through webcam. I am able to stop the stream of the webcam but the camera indicator does not turn off even after the stream has been stopped. It turns off when I reload the page. Here's the function I am using to stop the stream.

function stopStreamedVideo() {
    let videoElem = document.querySelector("#camera-content > video");
    const stream = videoElem.srcObject;
    const tracks = stream.getTracks();
    tracks.forEach(function (track) {
      track.stop();
    });
    videoElem.srcObject = null;
  }
  • Does this answer your question? [Closing webcam without reloading](https://stackoverflow.com/questions/52905393/closing-webcam-without-reloading) – GalAbra Oct 04 '20 at 07:20
  • No, @GalAbra, I have already checked that out. It doesn't help in my case as "react-webcam" is handling calling "getUserMedia" on behalf of me. – Raghav Sharma Oct 04 '20 at 17:04
  • Has anyone sorted this out? Really annoying this is so difficult. I'm unable to shut the camera off in a react hook where I initialize getUserMedia. I can shut it off in the same context where I start the camera but only when it's starting :/ – zero_cool Apr 20 '23 at 00:44

0 Answers0