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>