0

How to stop webcam (Close connection with camera) using getUserMedia in webRTC?

I tried with : localStream.getVideoTracks()[0].stop();

But it will not work for me in chrome. connection with the camera continues as it is.

My code is

navigator.getUserMedia = navigator.getUserMedia || 
 navigator.webkitGetUserMedia || navigator.mozGetUserMedia ||  
 navigator.msGetUserMedia || navigator.oGetUserMedia;

if(navigator.getUserMedia){
    navigator.getUserMedia({video: true}, handleVideo, videoError);
}

function handleVideo(stream) {
    localStream = stream;
    document.querySelector('#vidDisplay').src = window.URL.createObjectURL(stream);
};

function videoError(e)
{
    alert("There is some problem..");
};
Peter Szoldan
  • 4,792
  • 1
  • 14
  • 24
vivek dhamecha
  • 409
  • 3
  • 14
  • Duplicate Question, solution in this link https://stackoverflow.com/questions/11642926/stop-close-webcam-which-is-opened-by-navigator-getusermedia – Karthik May 08 '18 at 08:11
  • I tried using it @karthik but browser tab continues using the camera and black screen appears on view part. – vivek dhamecha May 09 '18 at 09:05

0 Answers0