Edit: I've seen the answer but I do I embed it in my code? I've done several attempts but no one works. Do I leave my variables and add the ones from previos answer of should I replace them? Any example? Thanks.
first of all: javascript noob speaking, so forgive my mistakes please.
I implemented the code below in order to stop a video stream after (x) seconds have passed. What this code does correctly is to pause the video but I would also the code to release the webcam and the microphone which, in fact, remain still engaged after the video has been paused.
I've found other questions related to this topic (release each of audio and video tracks) but the point is that none of them were embedded in a script like this which, as a main condition, has a countdown to zero. I've tried to implement them but none of them actually worked or, maybe, I couldn't implement them properly.
Any clue?
Thanks
<script>
var startTime = new Date().getTime();
var interval = setInterval(function() {
if (new Date().getTime() - startTime > 5000) {
var video =
document.getElementById("videoElement");
video.src = "";
video.pause();
}
});
var video = document.getElementById("video"),
vendorUrl = window.URL || window.webkitURL;
navigator.getMedia = navigator.getUserMedia ||
navigator.webkitGetUserMedia ||
navigator.mozGetUserMedia ||
navigator.oGetUserMedia ||
navigator.msGetUserMedia;
var video = document.querySelector("#videoElement");
if (navigator.mediaDevices.getUserMedia) {
navigator.mediaDevices.getUserMedia({
audio: true,
video: true
})
.then(function(stream) {
video.srcObject = stream;
})
}
</script>