mdn / samples-server

MDN samples server; used for samples that can't be hosted in-place on MDN, plus back-end server-side code for samples that need it.
https://developer.mozilla.org/
Creative Commons Zero v1.0 Universal
956 stars 929 forks source link

getUserMedia error: NotReadableError #43

Open Zubair-Iftikhar opened 7 years ago

Zubair-Iftikhar commented 7 years ago

Demo working on Google Chrome Version 58.0.3029.110 (64-bit) On Window 10( 64-bit) But not working on Firefox 54.0 (32-bit) i write you code with MediaDevices.getUserMedia()

`

// Older browsers might not implement mediaDevices at all, so we set an empty object first if (navigator.mediaDevices === undefined) { navigator.mediaDevices = {}; }

    // Some browsers partially implement mediaDevices. We can't just assign an object
    // with getUserMedia as it would overwrite existing properties.
    // Here, we will just add the getUserMedia property if it's missing.
    if (navigator.mediaDevices.getUserMedia === undefined) {
        navigator.mediaDevices.getUserMedia = function(constraints) {

            // First get ahold of the legacy getUserMedia, if present
            var getUserMedia = navigator.webkitGetUserMedia || navigator.mozGetUserMedia;

            // Some browsers just don't implement it - return a rejected promise with an error
            // to keep a consistent interface
            if (!getUserMedia) {
                return Promise.reject(new Error('getUserMedia is not implemented in this browser'));
            }

            // Otherwise, wrap the call to the old navigator.getUserMedia with a Promise
            return new Promise(function(resolve, reject) {
                getUserMedia.call(navigator, constraints, resolve, reject);
            });
        }
    }

    navigator.mediaDevices.getUserMedia({ audio: false, video: true })

    .then(function(stream) {
        var video = document.querySelector('video');
        // Older browsers may not have srcObject
        if ("srcObject" in video) {
            video.srcObject = stream;
            } else {
            // Avoid using this in new browsers, as it is going away.
            video.src = window.URL.createObjectURL(stream);
        }
        video.onloadedmetadata = function(e) {
            video.play();
        };
    })
    .catch(function(err) {
        //console.log(err.name + ": " + err.message);
        console.log('Error');
    });

`

still not working on Firefox... .catch runs... and show error msg "Error" in console. But Chrome still working....

MediaDevices

utkarsh2k2 commented 6 years ago

I have the same problem.

lvwanyou commented 6 years ago

Is the problem solved? i have the same question,too.