navigator.mozGetUserMedia未调用onvideosuccess方法



我正试图让一个网络应用程序与网络摄像头视频源一起运行,但我没有幸运地将视频源连接到firefox浏览器。以下是我的代码。

navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia;           
window.URL = window.URL || window.webkitURL || window.mozURL || window.msURL;
if(this.videoelement){
if(this.browser.hasVideoCameraSupport())
    navigator.getUserMedia({video: true, audio: true}, 
                      function(stream) { 
               this.videoelement.src = window.URL.createObjectURL(stream);
               this.videoStream = stream;
               this.videoRunning = true;
               if (typeof callback === "function")
                                callback(this.videoStream);
            }.bind(this) ,
                      function (err) {
            alert("Unknown Error "+err.message);
           }
             );
} else{
    alert("You HTML dom Does have a video element!");
}
}   

毕竟firefox已经决定更改API,并以不同的方式进行操作。我设法解决了这个问题,我的代码如下。

var videoelement = document.querySelector('video');     
        navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia;           
        window.URL = window.URL || window.webkitURL || window.mozURL || window.msURL;
        if(videoelement){
            navigator.getUserMedia({video: true, audio: false},
                        function(stream) { 
                            if (navigator.mozGetUserMedia) {
                                videoelement.mozSrcObject = stream;
                              } else {
                                var vendorURL = window.URL || window.webkitURL;
                                videoelement.src = vendorURL.createObjectURL(stream);
                              }
                            videoelement.play();                                
                }.bind(this) , function (err) {
                    alert("Unknown Error "+err.message);
                });
        } else{
            alert("You HTML dom Does have a video element!");
        }   

相关内容

  • 没有找到相关文章

最新更新