From: ScottDowne Date: Fri, 10 Dec 2010 16:53:47 +0000 (-0500) Subject: [#199] cleaned up readyState check X-Git-Tag: v0.2~52^2~13 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=3d9ff9b345921a927effcd053c6fd8ad8901e2be;p=popcorn-js.git [#199] cleaned up readyState check --- diff --git a/popcorn.js b/popcorn.js index b67e95c..e4d84f8 100644 --- a/popcorn.js +++ b/popcorn.js @@ -43,13 +43,14 @@ } }; - 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 ) { @@ -106,11 +107,11 @@ tracks.previousUpdateTime = currentTime; }, false); } else { - window.setTimeout(function() { waitForVideo(that); }, 1); + window.setTimeout(function() { isReady(that); }, 1); } }; - - waitForVideo(this); + + isReady(this); return this; } @@ -152,6 +153,19 @@ 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 ) { @@ -452,15 +466,9 @@ 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