Skip to content

Instantly share code, notes, and snippets.

@davidascher
Created August 8, 2013 03:34
Show Gist options
  • Select an option

  • Save davidascher/6181222 to your computer and use it in GitHub Desktop.

Select an option

Save davidascher/6181222 to your computer and use it in GitHub Desktop.
<element name="app-snapshot">
<template>
<button onclick="console.log(this); $(this).startVideo()">take a pix!</button>
<div class="videoscreen">
</div>
</template>
<script type="text/ceci">
Ceci(this, {
startVideo: function() {
try {
window.navigator.mozGetUserMedia(param, function(stream) {
content.appendChild(video);
video.mozSrcObject = stream;
video.play();
}, function(err) {
console.log(err);
stopMedia();
});
} catch(e) {
console.log(err);
stopMedia();
}
},
init: function () {
var video_status = false;
var video = document.createElement("video");
video.setAttribute("width", 640);
video.setAttribute("height", 480);
var content = document.getElementsByClassName("videoscreen")[0];
function startVideo() {
video_status = true;
startMedia({video:true});
}
function stopMedia() {
if (video_status) {
video.mozSrcObject.stop();
video.mozSrcObject = null;
content.removeChild(video);
// frames.innerHTML = '';
capturing = false;
video_status = false;
}
}
function startMedia(param) {
}
function captureImage() {
if (video_status && capturing) {
var canvas = document.createElement('canvas');
var ctx = canvas.getContext('2d');
canvas.width = video.videoWidth/4;
canvas.height = video.videoHeight/4;
ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
this.emit(canvas.toDataURL('image/png'));
}
}
},
editable: {
input: function(val, channel) {
}
}
});
</script>
</element>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment