]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
[#199] cleaned up readyState check
authorScottDowne <sdowne@learn.senecac.on.ca>
Fri, 10 Dec 2010 16:53:47 +0000 (11:53 -0500)
committerScottDowne <sdowne@learn.senecac.on.ca>
Fri, 10 Dec 2010 16:53:47 +0000 (11:53 -0500)
popcorn.js

index b67e95cc54c38d12444828021fd572d45ada4930..e4d84f834f1b0199b5605b7609a3fc5f87973fc9 100644 (file)
         }
       };
       
-      var waitForVideo = function(that) {
-        if (that.video.readyState >= 1) {
+      var isReady = function(that) {
+
+        if (that.video.readyState >= 3) {
           // adding padding to the front and end of the arrays
           // this is so we do not fall off either end
+
           var videoDurationPlus = that.video.duration + 1;
-          that.data.tracks.byStart.push({start: videoDurationPlus, end: videoDurationPlus});
-          that.data.tracks.byEnd.push({start: videoDurationPlus, end: videoDurationPlus});
+          Popcorn.addTrack(that, {start: videoDurationPlus, end: videoDurationPlus});
           
           that.video.addEventListener( "timeupdate", function( event ) {
 
             tracks.previousUpdateTime = currentTime;
           }, false);
         } else {
-          window.setTimeout(function() { waitForVideo(that); }, 1);
+          window.setTimeout(function() { isReady(that); }, 1);
         }
       };
-      
-      waitForVideo(this);
+
+      isReady(this);
 
       return this;
     }
     return dest;      
   };
 
+  Popcorn.addTrack = function( obj, track ) {
+    console.log(obj);
+    // Store this definition in an array sorted by times
+    obj.data.tracks.byStart.push( track );
+    obj.data.tracks.byEnd.push( track );
+    obj.data.tracks.byStart.sort( function( a, b ){
+      return ( a.start - b.start );
+    });
+    obj.data.tracks.byEnd.sort( function( a, b ){
+      return ( a.end - b.end );
+    });
+  };
+
   // A Few reusable utils, memoized onto Popcorn
   Popcorn.extend( Popcorn, {
        error: function( msg ) {
           setup._setup.call(self, options);
         }
         
-        // Store this definition in an array sorted by times
-        this.data.tracks.byStart.push( options );
-        this.data.tracks.byEnd.push( options );
-        this.data.tracks.byStart.sort( function( a, b ){
-          return ( a.start - b.start );
-        });
-        this.data.tracks.byEnd.sort( function( a, b ){
-          return ( a.end - b.end );
-        });
+
+        Popcorn.addTrack( this, options );
+
         
         //  Future support for plugin event definitions 
         //  for all of the native events