Skip to content

Instantly share code, notes, and snippets.

@hzyjerry
Forked from mxriverlynn/webcam.css
Last active August 29, 2015 14:28
Show Gist options
  • Save hzyjerry/2b39fe982525246ec1bc to your computer and use it in GitHub Desktop.
Save hzyjerry/2b39fe982525246ec1bc to your computer and use it in GitHub Desktop.
webrtc webcam in 20 lines
body {
margin: 0px;
padding: 0px;
}
#player {
width: 100%;
height: 100%;
}
<!doctype html>
<html>
<head>
<title>WebRTC WebCam</title>
<link rel="stylesheet" href="webcam.css"/>
<script src="webcam.js"></script>
</head>
<video id="player" autoplay="true"></video>
</html>
(function(){
var mediaOptions = { audio: false, video: true };
if (!navigator.getUserMedia) {
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia;
}
if (!navigator.getUserMedia){
return alert('getUserMedia not supported in this browser.');
}
navigator.getUserMedia(mediaOptions, success, function(e) {
console.log(e);
});
function success(stream){
var video = document.querySelector("#player");
video.src = window.URL.createObjectURL(stream);
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment