使用getUserMedia()API时出现404错误

Adi*_*pta 2 javascript google-chrome webrtc

我有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>
Run Code Online (Sandbox Code Playgroud)

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);
Run Code Online (Sandbox Code Playgroud)

因此,当我打开运行index.html时,出现错误-:8888 / getUserMedia / [object%20MediaStream]:1 GET http:// localhost:8888 / getUserMedia / [object%20MediaStream] getUserMedia不是一个函数。

我也在apache服务器上尝试过。但是有同样的错误。

Phi*_*cke 5

包括adapter.js并设置 video.srcObject = stream; 不推荐使用其他所有功能。