Pickels
Pickels

Reputation: 34632

WebRTC getUserMedia not showing video

I have the following code:

document.addEventListener('DOMContentLoaded', function () {

  var video = document.querySelector('video');

  window.navigator.webkitGetUserMedia({ video: true, audio: true }, function (stream) {

    var url = window.webkitURL.createObjectURL(stream);
    video.src = stream;

  }, function (err) {
    console.log('error: ', err);
  });

});

Html:

<!DOCTYPE html>
<html>
<head>
  <meta charset='utf-8'>
  <title>getUserMedia Video Example</title>
  <script src='index.js'></script>
</head>
<body>
  <video controls autoplay />
</body>
</html>

Why isn't it showing video?

Upvotes: 0

Views: 1811

Answers (1)

Šime Vidas
Šime Vidas

Reputation: 185873

You have to assign the url to video.src, not the stream:

navigator.webkitGetUserMedia({ video: true, audio: true }, function ( stream ) {
    video.src = window.webkitURL.createObjectURL( stream );
}, function ( err ) {
    console.log( 'error: ', err );
});​

Live demo: http://jsfiddle.net/FcTMk/2/ (Webkit only)

Upvotes: 2

Related Questions