admin管理员组

文章数量:1415062

I have index.html and app.js - index.html

<!DOCTYPE html>
<html>
<head>
  <title>Realtime munication with WebRTC</title>
  <link rel="stylesheet" href="css/main.css" />
</head>
<body>
  <h1>Realtime munication 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);

So when I open run index.html I got error - :8888/getUserMedia/[object%20MediaStream]:1 GET http://localhost:8888/getUserMedia/[object%20MediaStream] getUserMedia is not a function.

I also tried on apache server. But got same error.

I have index.html and app.js - index.html

<!DOCTYPE html>
<html>
<head>
  <title>Realtime munication with WebRTC</title>
  <link rel="stylesheet" href="css/main.css" />
</head>
<body>
  <h1>Realtime munication 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);

So when I open run index.html I got error - :8888/getUserMedia/[object%20MediaStream]:1 GET http://localhost:8888/getUserMedia/[object%20MediaStream] getUserMedia is not a function.

I also tried on apache server. But got same error.

Share Improve this question asked Jul 23, 2016 at 13:28 Aditya GuptaAditya Gupta 491 silver badge8 bronze badges 1
  • Did some stupid things. My code is all fine and working properly. I added different js file. Sorry! – Aditya Gupta Commented Jul 23, 2016 at 20:59
Add a ment  | 

2 Answers 2

Reset to default 6

include adapter.js and set video.srcObject = stream; Everything else is deprecated.

You just change

element.src = window.URL.createObjectURL(stream);

to:

element.srcObject = stream;
element.onloadedmetadata = function(e) { element.play(); };

本文标签: javascriptgot 404 error while using getUserMedia() APIStack Overflow