我有index.html和app.js - 的index.html
<!DOCTYPE html>
<html>
<head>
<title>Realtime communication with WebRTC</title>
<link rel="stylesheet" href="css/main.css" />
</head>
<body>
<h1>Realtime communication with WebRTC</h1>
<video autoplay></video>
<script src="js/main.js"></script>
</body>
</html>
app.js =&gt;
'use strict';
navigator.getUserMedia = navigator.getUserMedia ||
navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
var constraints = {
audio: false,
video: true
};
var video = document.querySelector('video');
function successCallback(stream) {
window.stream = stream; // stream available to console
if (window.URL) {
video.src = window.URL.createObjectURL(stream);
} else {
video.src = stream;
}
}
function errorCallback(error) {
console.log('navigator.getUserMedia error: ', error);
}
navigator.getUserMedia(constraints, successCallback, errorCallback);
所以当我打开运行index.html时 我收到了错误 - :8888 / getUserMedia / [object%20MediaStream]:1 GET http://localhost:8888/getUserMedia/[object%20MediaStream] getUserMedia不是一个函数。
我也尝试过apache服务器。但是得到了同样的错误。
答案 0 :(得分:4)
包括adapter.js并设置
video.srcObject = stream;
其他一切都被弃用了。
答案 1 :(得分:0)
您只需更改
element.src = window.URL.createObjectURL(stream);
收件人:
element.srcObject = stream;
element.onloadedmetadata = function(e) { element.play(); };