在webrtc中navigator.webkitGetUserMedia()和NavigatorUserMediaError附近找不到对象

Vic*_*tor 3 webrtc

当我尝试实现基本的示例应用程序时,我开始学习webrtc

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

<script type="text/javascript">
    navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia ||
    navigator.mozGetUserMedia || navigator.msGetUserMedia;
window.URL = window.URL || window.webkitURL;

navigator.getUserMedia({video: true}, function(localMediaStream) { 
  var video = document.createElement("video");
  video.autoplay = true;
  video.src = window.URL.createObjectURL(localMediaStream);
  document.body.appendChild(video);
}, function(error) {
  console.log(error);
});
</script>
</body> 
</html> 
Run Code Online (Sandbox Code Playgroud)

我使用此代码在locaL浏览器中运行google canary我启用了peerconnection并且我没有在我的浏览器中找到mediastream但我认为它可能在我的浏览器中启用了defalut.

问题是这个代码结果为console.i中的NavigatorUserMediaError没有找到解决这个问题的方法.任何人都知道我的代码出错了.

Sam*_*ton 6

你是从网络服务器上运行的吗?

如果从file:// URL运行它,您将获得NavigatorUserMediaError.

我刚刚在Chrome 22.0中尝试了localhost中的代码,它运行正常.

请注意,此示例不使用RTCPeerConnection,您现在不必在Chrome中启用任何标记.

  • 只需添加评论即可澄清(并检查我是否理解).当你从`file://`运行它时,`getUserMedia`不起作用,但当你在`localhost`上运行一个webserver并从中访问它时,它就没问题了. (2认同)