--- /dev/null
+var _stroke = 0; // current stroke
+var onPt = 0; // current point on stroke
+var onStroke = 0; // current point on stroke
+var start = +(new Date());
+var x, y, rotation = false;
+var strokes=0;
+var data = {};
+var toggle = 0;
+var ready = false;
+var play = function(){};
+var dur = 0;
+var options = {};
+var video = document.getElementById("video");
+
+// empty on purpose
+void setup() {}
+void draw() {
+
+ play();
+}
+
+void construct( data, options ) {
+
+ size(640,640);
+ frameRate(60);
+ smooth();
+ reset();
+ noLoop();
+
+ dur = (options.end - options.start);
+ drawingDur = (options.endDrawing - options.start);
+
+ this.options = options;
+
+ var si = setInterval(function() {
+
+ if (!data) return;
+ clearInterval(si);
+
+ this.data = data;
+ strokes = this.data.gml.tag.drawing.stroke;
+ var tag = this.data.gml.tag;
+ var app_name = tag.header && tag.header.client && tag.header.client.name;
+ rotation = app_name == 'Graffiti Analysis 2.0: DustTag' ||
+ app_name == 'DustTag: Graffiti Analysis 2.0' ||
+ app_name == 'Fat Tag - Katsu Edition';
+
+
+ play = function() {
+
+ if ( video.currentTime < options.endDrawing ) {
+ seek( ( video.currentTime - options.start ) / dur * strokes.pt.length );
+ }
+
+ };
+ }, 50);
+}
+
+
+void reset() {
+ background( 0 );
+ onPt = onStroke = 0;
+ x = y = null;
+}
+
+function drawLine(x,y,x2,y2) {
+ _x = rotation ? y*height : x*width;
+ _y = rotation ? width-(x*width) : y*height;
+ _x2 = rotation ? y2 * height : x2*width;
+ _y2 = rotation ? width - (x2 * width) : y2*height;
+ stroke(0);
+ strokeWeight(13);
+ strokeCap(SQUARE);
+ line(_x,_y,_x2,_y2);
+ stroke(255);
+ strokeWeight(12);
+ strokeCap(ROUND);
+ line(_x,_y,_x2,_y2);
+ //ol = { x: _x, y: _y, x2: _x2, y2: _y2 };
+}
+
+function seek( point ) {
+ if ( point < onPt ) reset();
+
+ var start; var hyp;
+ while (onPt <= point) {
+ if (!strokes) return;
+ _stroke = strokes.length ? strokes[onStroke] : strokes;
+ pt = _stroke.pt[onPt];
+ var p = onPt;
+ if (x !== null ) drawLine(x,y,pt.x,pt.y);
+ /*if (onPt) {
+if (++onPt >= _stroke.pt.length) {
+//if (!strokes.length || ++onStroke >= strokes.length) return reset();
+//onPt = 0;
+}
+}*/
+ x = pt.x;
+ y = pt.y;
+ if (onPt==p) onPt++; //went back to 0
+ }
+}
+
--- /dev/null
+<!DOCTYPE html>
+<html>
+<head>
+ <title>Popcorn attribution Plug-in Demo</title>
+
+ <script src="../../popcorn.js"></script>
+ <script src="popcorn.gml.js"></script>
+ <script>
+ document.addEventListener('DOMContentLoaded', function () {
+ var p = Popcorn('#video')
+ .play()
+ .volume(0)
+ .gml({
+ start: 0, // seconds
+ end: 10, // seconds
+ gmltag: '29582',
+ target: 'attribdiv'
+ });
+ /*.attribution({
+ start: 5, // seconds
+ end: 15, // seconds
+ nameofwork: "Internet",
+ nameofworkurl:"http://www.archive.org/details/CC1232_internet",
+ copyrightholder:"The Computer Chronicles",
+ license:"CC-BY-NC-ND",
+ licenseurl: "http://creativecommons.org/licenses/by-nc-nd/2.0/",
+ target: 'attribdiv'
+ } )*/
+
+ }, false);
+
+ </script>
+</head>
+<body>
+ <h1 id="qunit-header">Popcorn Attribution Plug-in Demo</h1>
+ <p> A attribution displaying 'A Shared Culture, Jesse Dylan, license: CC-BY-N6' will appear at 0 seconds and disappear at 10 seconds.</p>
+ <p> A attribution displaying 'Internet, The Computer Chronicles' will appear at 5 seconds and disappear at 15 seconds.</p>
+ <div>
+ <video id='video'
+ controls preload='none'
+ width= '250px'
+ poster="../../test/poster.png">
+
+ <source id='mp4'
+ src="../../test/trailer.mp4"
+ type='video/mp4; codecs="avc1, mp4a"'>
+
+ <source id='ogv'
+ src="../../test/trailer.ogv"
+ type='video/ogg; codecs="theora, vorbis"'>
+
+ <p>Your user agent does not support the HTML5 Video element.</p>
+
+ </video>
+ </div>
+ <div id="attribdiv" width="50%" height="50%">
+ </div>
+</body>
+</html>
--- /dev/null
+// PLUGIN: GML
+
+(function (Popcorn) {
+
+ var processingLoaded = false;
+
+ var ajax = function ajax(url) {
+
+ var xhr = new XMLHttpRequest();
+ xhr.open("GET", url, false);
+ xhr.setRequestHeader("If-Modified-Since", "Fri, 1 Jan 1960 00:00:00 GMT");
+ xhr.send(null);
+ // failed request?
+ if (xhr.status !== 200 && xhr.status !== 0) { throw ("XMLHttpRequest failed, status code " + xhr.status); }
+ return xhr.responseText;
+ };
+
+ Popcorn.getScript( "http://processingjs.org/content/download/processing-js-1.1.0/processing-1.1.0.js", function() {
+
+ processingLoaded = true;
+ });
+
+ /**
+*/
+ Popcorn.plugin( "gml" , {
+
+ /**
+*/
+ _setup : function( options ) {
+
+ var self = this;
+
+ options.endDrawing = options.endDrawing || options.end;
+ // create a canvas to put in the target div
+ options.container = document.createElement( 'canvas' );
+
+ options.container.style.display = "none";
+ options.container.setAttribute( 'id', 'canvas' + options.gmltag );
+
+ if ( document.getElementById( options.target ) ) {
+ document.getElementById( options.target ).appendChild( options.container );
+ }
+
+
+ // makes sure both processing.js and the gml player are loaded
+ var readyCheck = setInterval(function() {
+
+ if ( !processingLoaded ) {
+
+ return;
+ }
+
+ clearInterval(readyCheck);
+ Popcorn.getJSONP( "http://000000book.com/data/" + options.gmltag + ".json?callback=", function( data ) {
+
+ new Processing( options.container, ajax( "gmlplayer.js" ) );
+ options.pjsInstance = Processing.getInstanceById( 'canvas' + data.id );
+ options.pjsInstance.construct( data, options );
+ options._running && options.pjsInstance.loop();
+ }, false );
+ }, 5);
+ },
+ /**
+*/
+ start: function( event, options ) {
+
+ options.pjsInstance && options.pjsInstance.loop();
+ options.container.style.display = "block";
+ },
+ /**
+*/
+ end: function( event, options ) {
+
+ options.pjsInstance && options.pjsInstance.noLoop();
+ options.container.style.display = "none";
+ }
+ });
+})( Popcorn );