Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getUserMedia frozen at first frame on Android Chrome

I have a working code on desktop browsers supporting getUserMedia Api, I can correctly see a video preview of my webcam in the div videoPreview. However, when running on Android device, this same code takes a picture with my front camera when I accept to share it in Chrome browser, then the preview keeps frozen on this first frame.

navigator.getMedia = (navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia);

    navigator.getMedia(
        // constraints
        {video:true, audio:false},

        // success callback
        function (mediaStream) {
            var video = document.getElementById('videoPreview');
            video.src = window.URL.createObjectURL(mediaStream);
            video.play();
        },   
        //handle error
        function (error) {
            console.log(error);
        }
    )  
like image 905
Emmanuel Scarabin Avatar asked Dec 05 '22 21:12

Emmanuel Scarabin


1 Answers

For those encountering same problem : I fixed it by adding autoplay attribute to my <video> tag.

Was stuck with this for a while, I hope this will help someone else.

like image 161
Emmanuel Scarabin Avatar answered Jan 15 '23 13:01

Emmanuel Scarabin