我有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 =>
'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服务器上尝试过。但是有同样的错误。
最佳答案
包括adapter.js并设置video.srcObject = stream;
其他所有东西都已弃用。
关于javascript - 使用getUserMedia()API时出现404错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/38542318/