【发布时间】:2014-04-16 05:24:46
【问题描述】:
如何在 Chrome 和 Mozilla 等浏览器中启用 WebRTC 视频(以及音频)查看。
我使用的代码是这样的
HTML:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title> WebRTC</title>
</head>
<body>
<video id="peer2-to-peer1" autoplay controls style="width:40%;"></video>
<script src="script.js"></script>
</body>
</html>
javascript 文件:
navigator.getUserMedia ||
(navigator.getUserMedia = navigator.mozGetUserMedia ||
navigator.webkitGetUserMedia || navigator.msGetUserMedia);
if (navigator.getUserMedia) {
navigator.getUserMedia({
audio: true
}, function(localMediaStream) {alert('in');
var video = document.querySelector('video');
video.src = window.URL.createObjectURL(localMediaStream);
video.onloadedmetadata = function(e) {
// Do something with the video here.
};
}, onError);
} else {
alert('getUserMedia is not supported in this browser.');
}
function onSuccess() {
alert('Successful!');
}
function onError() {
alert('There has been a problem retrieving the streams - did you allow access?');
}
但是,
我收到一个错误,因为没有调用 onSuccess 函数。
链接:
http://www.creativebloq.com/javascript/get-started-webrtc-1132857
【问题讨论】:
标签: webrtc