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?
You have to assign the
urltovideo.src, not thestream:Live demo: http://jsfiddle.net/FcTMk/2/ (Webkit only)