From 801fb2d1e9e9292c344748aa528bfcbc850401c5 Mon Sep 17 00:00:00 2001 From: rwldrn Date: Thu, 24 Mar 2011 10:58:00 -0400 Subject: [PATCH] [#450] Complete audio support; Complete auto-load data-timeline-sources support --- parsers/parserJSON/data/audio.json | 49 +++++++++ parsers/parserJSON/data/video.json | 49 +++++++++ .../parserJSON/popcorn.parserJSON.unit.html | 18 +++- parsers/parserJSON/popcorn.parserJSON.unit.js | 102 ++++++++++++++++-- popcorn.js | 8 +- test/index.html | 2 +- test/popcorn.unit.js | 12 +-- 7 files changed, 216 insertions(+), 24 deletions(-) create mode 100644 parsers/parserJSON/data/audio.json create mode 100644 parsers/parserJSON/data/video.json diff --git a/parsers/parserJSON/data/audio.json b/parsers/parserJSON/data/audio.json new file mode 100644 index 0000000..d867f92 --- /dev/null +++ b/parsers/parserJSON/data/audio.json @@ -0,0 +1,49 @@ +{ + "title":"Crockford Lives!", + "remote":"http://dl.dropbox.com/u/3531958/crockford.ogv", + "data": [ + { + "webpage": { + "start":"0.0897589878863602", + "end":"2.001204869833337", + "target":"audio-iframe-container", + "src":"http://json.org" + } + }, + { + "footnote": { + "start":"0.23530116023787565", + "end":"2.0193976413772767", + "target":"audio-footnote-container", + "text":"I invented JSON" + } + }, + { + "googlemap": { + "start":"0.09096385771969716", + "end":"8.617349362660605", + "target":"audio-map-container", + "type":"ROADMAP", + "lat":37.7749295, + "lng":-122.4194155, + "location":"San Francisco, CA" + } + }, + { + "webpage": { + "start":"2.073975956009095", + "end":"10.278915922325776", + "target":"audio-iframe-container", + "src":"http://jslint.org" + } + }, + { + "footnote": { + "start":2.145542172351516, + "end":10.145542172351513, + "target":"audio-footnote-container", + "text":"I wrote JSLint" + } + } + ] +} diff --git a/parsers/parserJSON/data/video.json b/parsers/parserJSON/data/video.json new file mode 100644 index 0000000..1da4657 --- /dev/null +++ b/parsers/parserJSON/data/video.json @@ -0,0 +1,49 @@ +{ + "title":"Crockford Lives!", + "remote":"http://dl.dropbox.com/u/3531958/crockford.ogv", + "data": [ + { + "webpage": { + "start":"0.0897589878863602", + "end":"2.001204869833337", + "target":"video-iframe-container", + "src":"http://json.org" + } + }, + { + "footnote": { + "start":"0.23530116023787565", + "end":"2.0193976413772767", + "target":"video-footnote-container", + "text":"I invented JSON" + } + }, + { + "googlemap": { + "start":"0.09096385771969716", + "end":"8.617349362660605", + "target":"video-map-container", + "type":"ROADMAP", + "lat":37.7749295, + "lng":-122.4194155, + "location":"San Francisco, CA" + } + }, + { + "webpage": { + "start":"2.073975956009095", + "end":"10.278915922325776", + "target":"video-iframe-container", + "src":"http://jslint.org" + } + }, + { + "footnote": { + "start":2.145542172351516, + "end":10.145542172351513, + "target":"video-footnote-container", + "text":"I wrote JSLint" + } + } + ] +} diff --git a/parsers/parserJSON/popcorn.parserJSON.unit.html b/parsers/parserJSON/popcorn.parserJSON.unit.html index 4fcce42..fdb02d0 100644 --- a/parsers/parserJSON/popcorn.parserJSON.unit.html +++ b/parsers/parserJSON/popcorn.parserJSON.unit.html @@ -41,14 +41,26 @@

Your user agent does not support the HTML5 Video element.

+ + + -
-
-
+
+
+
+
+
+
+
+
+
+
+
diff --git a/parsers/parserJSON/popcorn.parserJSON.unit.js b/parsers/parserJSON/popcorn.parserJSON.unit.js index 6312a2f..e6ecb0b 100644 --- a/parsers/parserJSON/popcorn.parserJSON.unit.js +++ b/parsers/parserJSON/popcorn.parserJSON.unit.js @@ -7,18 +7,15 @@ test("Popcorn 0.3 JSON Parser Plugin", function () { finished = false, trackData, trackEvents, - interval, poppercorn = Popcorn( "#video" ); function plus() { if ( ++count === expects ) { start(); - // clean up added events after tests - clearInterval( interval ); } } - poppercorn.parseJSON("data/data.json"); + poppercorn.parseJSON("data/video.json"); expect(expects); @@ -29,14 +26,17 @@ test("Popcorn 0.3 JSON Parser Plugin", function () { trackEvents = trackData.trackEvents; Popcorn.xhr({ - url: 'data/data.json', + url: 'data/video.json', success: function( data ) { var idx = 0; + //console.log( data ); + Popcorn.forEach( data.json.data, function (dataObj) { - Popcorn.forEach( dataObj, function ( obj, key ) { + //console.log( dataObj ); + Popcorn.forEach( dataObj, function ( obj, key ) { equals( trackData.history[idx].indexOf(key), 0, "history item '" + trackData.history[idx] + "' matches data key '"+ key+ "' at correct index" ); plus(); @@ -59,11 +59,11 @@ test("Popcorn 0.3 JSON Parser Plugin", function () { plus(); - equals( $("#iframe-container").children().length, 2, '$("#iframe-container").children().length' ) + equals( $("#video-iframe-container").children().length, 2, '$("#video-iframe-container").children().length' ) plus(); - equals( $("#map-container").children().length, 1, '$("#map-container").children().length' ); + equals( $("#video-map-container").children().length, 1, '$("#video-map-container").children().length' ); plus(); - equals( $("#footnote-container").children().length, 2, '$("#footnote-container").children().length' ); + equals( $("#video-footnote-container").children().length, 2, '$("#video-footnote-container").children().length' ); plus(); this.pause(); @@ -80,3 +80,87 @@ test("Popcorn 0.3 JSON Parser Plugin", function () { }, 500); }); + +test("Popcorn 0.3 JSON Parser Plugin - AUDIO", function () { + + var expects = 9, + count = 0, + timeOut = 0, + numLoadingEvents = 5, + finished = false, + trackData, + trackEvents, + interval, + audiocorn = Popcorn.getInstanceById("audio"); + + function plus() { + if ( ++count === expects ) { + start(); + // clean up added events after tests + clearInterval( interval ); + } + } + + expect(expects); + + stop( 5000 ); + + + trackData = audiocorn.data; + trackEvents = trackData.trackEvents; + + + Popcorn.xhr({ + url: 'data/audio.json', + success: function( data ) { + + var idx = 0; + + Popcorn.forEach( data.json.data, function (dataObj) { + Popcorn.forEach( dataObj, function ( obj, key ) { + + + equals( trackData.history[idx].indexOf(key), 0, "history item '" + trackData.history[idx] + "' matches data key '"+ key+ "' at correct index" ); + plus(); + + idx++; + }); + }); + + + } + }); + audiocorn.listen("timeupdate", function ( event ) { + + + if ( Math.round( this.currentTime()) === 3 && !finished ) { + + finished = true; + + equals( trackEvents.byStart.length, numLoadingEvents + 2 , "trackEvents.byStart.length === (5 loaded, 2 padding) " ); + plus(); + + + equals( $("#audio-iframe-container").children().length, 2, '$("#audio-iframe-container").children().length' ) + plus(); + equals( $("#audio-map-container").children().length, 1, '$("#audio-map-container").children().length' ); + plus(); + equals( $("#audio-footnote-container").children().length, 2, '$("#audio-footnote-container").children().length' ); + plus(); + + this.pause(); + + } + + + }); + + + setTimeout(function () { + + audiocorn.currentTime(0).play() + + }, 500); + +}); + diff --git a/popcorn.js b/popcorn.js index 92fcc53..e12fa5a 100644 --- a/popcorn.js +++ b/popcorn.js @@ -1101,9 +1101,9 @@ document.addEventListener( "DOMContentLoaded", function () { - var medias = document.querySelectorAll( "video,audio" ); + var dataAttr = "data-timeline-sources", + medias = document.querySelectorAll( "video,audio" ); - Popcorn.forEach( medias, function( idx, key ) { var media = medias[ key ], @@ -1122,9 +1122,7 @@ popcornMedia = Popcorn( "#" + media.id ); - dataSources = ( media.getAttribute( "data-timeline-sources" ) || "" ).split(","); - - + dataSources = ( media.getAttribute( dataAttr ) || "" ).split(","); if ( dataSources[ 0 ] ) { diff --git a/test/index.html b/test/index.html index c075015..77eb56b 100644 --- a/test/index.html +++ b/test/index.html @@ -47,7 +47,7 @@ -