Created
January 2, 2013 11:24
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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