I'm encountering an issue with my camera functionality. I've implemented a button to open the camera (see code below), but I'm unsure how to turn off the camera when the same button is clicked.
Snippet of my code:
Button:
<a type="button" onclick="cameraOff()" name="button" id="button"> <i class="fas fa-video fa-2x cam-btn"></i> </a>
<video id="video" width="640" height="480" autoplay></video>
<script>
function cameraOff() {
var video = document.getElementById('video');
if (navigator.mediaDevices && navigator.mediaDevices.getUserMedia) {
navigator.mediaDevices.getUserMedia({
video: true
}).then(function(stream) {
video.srcObject = stream;
video.play();
});
}
}
</script>