Skip to content

Instantly share code, notes, and snippets.

@tonyjcamp
Created March 10, 2012 06:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tonyjcamp/2010556 to your computer and use it in GitHub Desktop.
Save tonyjcamp/2010556 to your computer and use it in GitHub Desktop.
OMG I NEED TO HURRY!
var doc = document,
snapshot = doc.getElementById('snapshot'),
photo = snapshot.getContext('2d'),
video = doc.querySelector('video'),
VIDEO_WIDTH, VIDEO_HEIGHT,
computeSize = function(supportsObjectFit){
// user agents that don't support object-fit
// will display the video with a different
// aspect ratio.
if (supportsObjectFit === true){
VIDEO_WIDTH = 640;
VIDEO_HEIGHT = 480;
} else {
VIDEO_WIDTH = video.videoWidth;
VIDEO_HEIGHT = video.videoHeight;
}
},
successCallback = function (stream) {
video.src = stream;
video.play();
computeSize(true);
},
errorCallback =function (error) {
console.error('An error occurred: [CODE ' + error.code + ']');
computeSize(true);
};
doc.getElementById('take').onclick = function() {
computeSize(true);
photo.drawImage(video, 0, 0, VIDEO_WIDTH, VIDEO_HEIGHT);
};
window.addEventListener('DOMContentLoaded', function() {
if (navigator.getUserMedia) {
navigator.getUserMedia({'video': true}, successCallback, errorCallback);
} else if (navigator.webkitGetUserMedia) {
navigator.webkitGetUserMedia("video", function(stream){
video.src = window.webkitURL.createObjectURL(stream);
video.play();
computeSize(false);
});
} else {
console.log('Native web camera streaming (getUserMedia) is not supported in this browser.');
}
}, false);
@beratetik
Copy link

Hey @tonyjcamp , need yo update line 19.

video.srcObject = stream

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment