1
How do I pause the camera and microphone stream within the method getUserMedia
?
I have my code like this:
navigator.getUserMedia({ video: true, audio: true },
function (MediaStream) {
var video = document.querySelector('#videoRecord');
video.src = window.URL.createObjectURL(MediaStream);
stream = MediaStream;
var mediaRecorder = new MediaRecorder(MediaStream);
// como pausar aqui o stream e depois iniciar novamente?
}, errorCallback);
If I use
MediaStream.getAudioTracks()[0].stop();
MediaStream.getVideoTracks()[0].stop();
camera light turns off, but I don’t know how to put the stream back on, since I do everything within the function getUserMedia
, so I don’t know if it would make sense to use one more getUserMedia
within what already exists.
My problem is that the browser indicates that there is still webcam/audio capture even when pausing, as in your example too.
– ihavenokia
What I have is this: The person records a video, when he clicks stop I show the video that he recorded, and meanwhile I stop at Mediastream, if he wants to record again I need to put the camera and microphone in Mediastream again.
– ihavenokia
@ihavenokia then is not pausing right friend? : ) But all right gave to understand now, I will make an example in a few minutes warning you
– Guilherme Nascimento
@ihavenokia created an example https://jsfiddle.net/x0gnrLt0/5/ can test, updated the answer as well.
– Guilherme Nascimento