Skip to content

Instantly share code, notes, and snippets.

@y-lohse
Created January 2, 2013 11:24
Show Gist options
  • Save y-lohse/4433936 to your computer and use it in GitHub Desktop.
Save y-lohse/4433936 to your computer and use it in GitHub Desktop.
A cross-browser way to start a video stream. Here the video element is created and appended to the DOM, but you could as well use a pre-existing video element.
function getVideo(){
var videoElement = document.createElement('video');
document.body.appendChild(videoElement);
var getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia ||
navigator.mozGetUserMedia || navigator.msGetUserMedia;
var params = [
{video: true},
function(stream){
try{
videoElement.src = window.URL.createObjectURL(stream);
}
catch (e){
videoElement.src = stream;
}
videoElement.play();
},
function(){
console.log('failed');
}];
getUserMedia.apply(navigator, params);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment