]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
[#450] Complete audio support; Complete auto-load data-timeline-sources support
authorrwldrn <waldron.rick@gmail.com>
Thu, 24 Mar 2011 14:58:00 +0000 (10:58 -0400)
committerrwldrn <waldron.rick@gmail.com>
Thu, 24 Mar 2011 14:58:00 +0000 (10:58 -0400)
parsers/parserJSON/data/audio.json [new file with mode: 0644]
parsers/parserJSON/data/video.json [new file with mode: 0644]
parsers/parserJSON/popcorn.parserJSON.unit.html
parsers/parserJSON/popcorn.parserJSON.unit.js
popcorn.js
test/index.html
test/popcorn.unit.js

diff --git a/parsers/parserJSON/data/audio.json b/parsers/parserJSON/data/audio.json
new file mode 100644 (file)
index 0000000..d867f92
--- /dev/null
@@ -0,0 +1,49 @@
+{\r
+  "title":"Crockford Lives!",\r
+  "remote":"http://dl.dropbox.com/u/3531958/crockford.ogv",\r
+  "data": [\r
+    {\r
+      "webpage":  {\r
+        "start":"0.0897589878863602",\r
+        "end":"2.001204869833337",\r
+        "target":"audio-iframe-container",\r
+        "src":"http://json.org"\r
+      }\r
+    },\r
+    {\r
+      "footnote": {\r
+        "start":"0.23530116023787565",\r
+        "end":"2.0193976413772767",\r
+        "target":"audio-footnote-container",\r
+        "text":"I invented JSON"\r
+      }\r
+    },\r
+    {\r
+      "googlemap":  {\r
+        "start":"0.09096385771969716",\r
+        "end":"8.617349362660605",\r
+        "target":"audio-map-container",\r
+        "type":"ROADMAP",\r
+        "lat":37.7749295,\r
+        "lng":-122.4194155,\r
+        "location":"San Francisco, CA"\r
+      }\r
+    },\r
+    {\r
+      "webpage":  {\r
+        "start":"2.073975956009095",\r
+        "end":"10.278915922325776",\r
+        "target":"audio-iframe-container",\r
+        "src":"http://jslint.org"\r
+      }\r
+    },\r
+    { \r
+      "footnote": {\r
+        "start":2.145542172351516,\r
+        "end":10.145542172351513,\r
+        "target":"audio-footnote-container",\r
+        "text":"I wrote JSLint"\r
+      }\r
+    }\r
+  ]\r
+}\r
diff --git a/parsers/parserJSON/data/video.json b/parsers/parserJSON/data/video.json
new file mode 100644 (file)
index 0000000..1da4657
--- /dev/null
@@ -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"
+      }
+    }
+  ]
+}
index 4fcce423e83b8381f20bb93910811a2b700e6583..fdb02d0e1d54804e993447ab648962fad6d06d77 100644 (file)
     <p>Your user agent does not support the HTML5 Video element.</p> 
 
   </video> 
+
+       <audio id='audio' src="../../test/italia.ogg" data-timeline-sources="data/audio.json" controls> 
+       </audio>
+  
   <style>
     .displays {
       width: 300px;
       height: 300px;
     }
   </style>
-  <div class="displays" id="iframe-container"></div>
-  <div class="displays" id="map-container"></div>
-  <div class="displays" id="footnote-container"></div> 
+  <hr>
+  <div style="width:300px;float:left">
+               <div class="displays" id="video-iframe-container"></div>
+               <div class="displays" id="video-map-container"></div>
+               <div class="displays" id="video-footnote-container"></div> 
+       </div>
+       <div style="width:300px;float:left">
+               <div class="displays" id="audio-iframe-container"></div>
+               <div class="displays" id="audio-map-container"></div>
+               <div class="displays" id="audio-footnote-container"></div>   
+       </div>
 </body>
 </html>
index 6312a2f187d0aadd8b687f7c38e355a42dad0e62..e6ecb0b472767d99556530786cee49af6506152b 100644 (file)
@@ -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);
+  
+});
+
index 92fcc5315674cfec75a95d63c1cec6d0490e2b5b..e12fa5a636fde16faa363f07d9270d73d56a7982 100644 (file)
 
   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 ],
 
         popcornMedia = Popcorn( "#" + media.id );
 
-        dataSources = ( media.getAttribute( "data-timeline-sources" ) || "" ).split(",");
-
-        
+        dataSources = ( media.getAttribute( dataAttr ) || "" ).split(",");
 
         if ( dataSources[ 0 ] ) {
 
index c075015ba2a4292f65d750364e83ca80044826e1..77eb56b77fd32ee2486a4f8b44af7ef85b9a06bc 100644 (file)
@@ -47,7 +47,7 @@
 
   </video>
 
-       <audio id='audio' src="italia.ogg" data-timeline-sources="data/parserData.json" controls> 
+       <audio id='audio' src="italia.ogg" controls> 
        </audio>
 </body>
 </html>
index cd32b5355fcebfdbe63ca31a0f9d52b837e78a21..17cce421acd212612a7cdaddfe6befb83feb46bc 100755 (executable)
@@ -99,7 +99,7 @@ test("Instances", function() {
   
   ok( "length" in Popcorn.instances && "join" in Popcorn.instances, "Popcorn.instances is a provided cache array");  
   plus();
-  
+
   instance = Popcorn.getInstanceById("video");
   
   ok( instance.video, "Stored instance as a `video` property" );
@@ -1918,11 +1918,11 @@ test("Parser Support", function () {
     }
   });
 
-  Popcorn.parser( "parseAudio", function( data ){
-    ok( typeof data.json === "object", "data.json exists");
-    plus();
-    return data.json;
-  });
+       Popcorn.parser( "parseAudio", function( data ){
+         ok( typeof data.json === "object", "data.json exists");
+         plus();
+         return data.json;
+       });
 
   audiocorn.parseAudio("data/parserAudio.json", function() {