mardi 4 mai 2021

Open Close Camera with same button Javascript

I have a problem. When I click the camera button (there is the code below) I can open the camera, but how can I turn the camera off when I click the same button.

A part 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>



Aucun commentaire:

Enregistrer un commentaire