A Pen by Shae Kuronen on CodePen.
Last active
August 29, 2015 13:56
-
-
Save shaekuronen/9037085 to your computer and use it in GitHub Desktop.
A Pen by Shae Kuronen.
This file contains hidden or 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
<button id="trigger">Get User Media</button> | |
<video id="video-player"></video> | |
<h4 id="error-message"></h4> | |
This file contains hidden or 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
var video = document.getElementById('video-player'), | |
error = document.getElementById('error-message'), | |
trigger = document.getElementById('trigger'); | |
navigator.getUserMedia = ( | |
navigator.getUserMedia || | |
navigator.webkitGetUserMedia || | |
navigator.mozGetUserMedia || | |
navigator.msGetUserMedia | |
); | |
function get_user_media() { | |
navigator.getUserMedia( | |
// constraints | |
{ video: true, audio: false }, | |
// success callback | |
function(stream) { | |
if (navigator.mozGetUserMedia) { | |
video.mozSrcObject = stream; | |
} else { | |
var vendorURL = window.URL || webkitWindowURL; | |
video.src = vendorURL.createObjectURL(stream); | |
} | |
video.play(); | |
}, | |
// error callback | |
function(error) { | |
error.innerHTML = 'There error is: ' + error; | |
} | |
); | |
} | |
trigger.addEventListener('click', function() { | |
get_user_media(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment