diff options
Diffstat (limited to 'js/camera.js')
| -rw-r--r-- | js/camera.js | 101 |
1 files changed, 51 insertions, 50 deletions
diff --git a/js/camera.js b/js/camera.js index 3a0c8b4..e03586a 100644 --- a/js/camera.js +++ b/js/camera.js @@ -1,61 +1,62 @@ var camera = (function(){ - var loaded = false, video + var loaded = false, video - navigator.getMedia = ( navigator.getUserMedia || - navigator.webkitGetUserMedia || - navigator.mozGetUserMedia || - navigator.msGetUserMedia); + navigator.getMedia = ( navigator.getUserMedia || + navigator.webkitGetUserMedia || + navigator.mozGetUserMedia || + navigator.msGetUserMedia); if (! navigator.getMedia) { $("#camera").hide() return } - $("#camera").click(load) - function load(){ - if (! loaded) { - build() - } - else { - ready() - } - window.gif = window.img = null - } + $("#camera").click(load) + + function load(){ + if (! loaded) { + build() + } + else { + ready() + } + window.gif = window.img = null + } - function ready(){ - cc.canvas.width = actual_w = w = min(video.videoWidth, 400) - cc.canvas.height = actual_h = h = video.videoHeight / (video.videoWidth/w) - video.setAttribute('width', video.videoWidth) - video.setAttribute('height', video.videoHeight) - window.gif = window.img = null - window.cam = video - } - - function build(){ - video = document.createElement("video") - navigator.getMedia({ - video: true, - audio: false - }, - function(stream) { - if (navigator.mozGetUserMedia) { - video.mozSrcObject = stream; - } else { - var vendorURL = window.URL || window.webkitURL; - video.src = vendorURL.createObjectURL(stream); - } - video.play(); - }, - function(err) { - console.log("An error occured! " + err); - } - ) + function ready(){ + cc.canvas.width = actual_w = w = min(video.videoWidth, 400) + cc.canvas.height = actual_h = h = video.videoHeight / (video.videoWidth/w) + video.setAttribute('width', video.videoWidth) + video.setAttribute('height', video.videoHeight) + window.gif = window.img = null + window.cam = video + } + + function build(){ + video = document.createElement("video") + navigator.getMedia({ + video: true, + audio: false + }, + function(stream) { + if (navigator.mozGetUserMedia) { + video.mozSrcObject = stream; + } else { + var vendorURL = window.URL || window.webkitURL; + video.src = vendorURL.createObjectURL(stream); + } + video.play(); + }, + function(err) { + console.log("An error occured! " + err); + } + ) - video.addEventListener('canplay', function(ev){ - if (! loaded) { - loaded = true - ready() - } - }, false); - } + video.addEventListener('canplay', function(e){ + if (! loaded) { + loaded = true + ready() + } + }, false); + } })() |
