Created
November 12, 2012 12:45
-
-
Save xl1/4059205 to your computer and use it in GitHub Desktop.
カメラから映像とるやつ
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
class window.WebCam | |
constructor: -> | |
@video = document.createElement('video') | |
init: (playCallback, failCallback) -> | |
userMedia = navigator.getUserMedia or navigator.webkitGetUserMedia | |
if not userMedia | |
return failCallback?() | |
@video.addEventListener('canplay', => @video.play()) | |
@video.addEventListener('timeupdate', => | |
@width = @video.videoWidth | |
@height = @video.videoHeight | |
if @width or @height | |
@video.removeEventListener('timeupdate', arguments.callee, false) | |
playCallback?() | |
, false) | |
setSourceURL = (src) => | |
url = window.URL or window.webkitURL | |
@video.src = if url then url.createObjectURL(src) else src | |
userMedia.call(navigator, | |
{ video: true, toString: -> 'video' }, setSourceURL, failCallback) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment