以下是代码部分,测试过,浏览器支持getUserMedia方法的。我实在找不出错误,两个回调函数函数都没有进入。求解!!!
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>WebRTC通信</title>
</head>
<body>
<h1>访问本地摄像头</h1>
<video id="myVideo" width="1024" height="888" autoplay="true"></video>
</body>
<script type="text/javascript">
window.onload = function(){
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
window.URL = window.URL || window.webkitURL;
navigator.getUserMedia({
video:true,
audio:true
},
//访问本地设备成功时的回调函数
//stream为同步媒体数据流
function(stream) {
var video = document.getElementById('myVideo');
if (window.URL) {
video.src = window.URL.createObjectURL(stream);
}else{
video.src = stream;
}
},
//访问本地设备失败时的回调函数
function (err) {
console.log(err);
});
}
</script>
</html>
慕桂英5329086
qq_雷人之锤_0
相关分类