Created
March 10, 2012 06:22
-
-
Save tonyjcamp/2010556 to your computer and use it in GitHub Desktop.
OMG I NEED TO HURRY!
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
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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey @tonyjcamp , need yo update line 19.
video.srcObject = stream