您的浏览器不支持navigator.getUserMedia接口

时间:2020-07-29 03:44:36

标签: javascript browser webrtc getusermedia mediadevices

我尝试将已弃用的navigator.getUserMedia()更改为navigator.mediaDevices.getUserMedia(),但似乎无济于事。界面显示我的浏览器不支持navigator.getUserMedia() 这样的想法是让我的浏览器提示我的网络摄像头,但它似乎不起作用。有帮助吗?

var video = document.querySelector('#camera-stream'),
    image = document.querySelector('#snap'),
    start_camera = document.querySelector('#start-camera'),
    controls = document.querySelector('.controls'),
    take_photo_btn = document.querySelector('#take-photo'),
    delete_photo_btn = document.querySelector('#delete-photo'),
    download_photo_btn = document.querySelector('#download-photo'),
    error_message = document.querySelector('#error-message');


// The getUserMedia interface is used for handling camera input.
// Some browsers need a prefix so here we're covering all the options
navigator.getUserMedia = ( navigator.getUserMedia ||
navigator.webkitGetUserMedia ||
navigator.mozGetUserMedia ||
navigator.msGetUserMedia);


if(!navigator.getUserMedia){
    displayErrorMessage("Your browser doesn't have support for the navigator.getUserMedia interface.");
}
else{

    // Request the camera.
    navigator.mediaDevices.getUserMedia(
        {
            video: true
        },
        // Success Callback
        function(stream){

            // Create an object URL for the video stream and
            // set it as src of our HTLM video element.
            video.src = window.URL.createObjectURL(stream);

            // Play the video element to start the stream.
            video.play();
            video.onplay = function() {
                showVideo();
            };
     
        },
        // Error Callback
        function(err){
            displayErrorMessage("There was an error with accessing the camera stream: " + err.name, err);
        }
    );

}

[这是输出] [1] [1]:https://i.stack.imgur.com/s2QMx.png

0 个答案:

没有答案