2

我一直在使用HTML5 <video>元素,它在Chrome和Firefox中均可用,但由于某些原因,它不起作用当我从文件加载它时在Chrome中本地,但它会在Firefox中工作。HTML5 <video>在Chrome中使用navigator.getUserMedia()

例子:http://codepen.io/asolar/pen/BoyPxZ

谁能告诉我为什么不工作,确实在工作火狐当它的文件?是否有某种类型的安全设置可以在Chrome中更改?

<html> 
<head> 
</head> 
<body> 

    <div> 
    <video id="camera" width="640" height="480" autoplay style="display: inline;"></video> 
    </div> 

    <script type="text/javascript"> 

    window.addEventListener('load', function() {Video();}, false); 

    // Setup the Audio and Video 
    function Video() { 

    navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia; 
    window.URL = window.URL || window.webkitURL || window.msURL || window.mozURL; 

    var constraints = {video: true, audio: true}; 
    navigator.getUserMedia(constraints, (function(stream) 
    { 
     PlayVideo(stream); 
     //PlayAudio(stream); 
    }), 
    (function(err) { 
     console.log("The following error occured: " + err.name); 
    })); 
    } 

    // play the <video> 
    function PlayVideo(stream) { 
    video = document.querySelector('video'); 
    video.src = window.URL.createObjectURL(stream); 
    video.onloadedmetadata = function(e) { 
     video.play(); 
    } 
    } 

    </script> 

</body> 
</html> 

回答

相关问题