From: ScottDowne Date: Thu, 25 Aug 2011 19:23:27 +0000 (-0400) Subject: merged timeupdate fix in to develop X-Git-Tag: v0.8^2~9^2 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=b0141ab0bd1e7c1371f349ff04a408fcfe7c4d31;p=popcorn-js.git merged timeupdate fix in to develop --- b0141ab0bd1e7c1371f349ff04a408fcfe7c4d31 diff --cc popcorn.js index 8a75c50,54592f8..7dad744 --- a/popcorn.js +++ b/popcorn.js @@@ -213,100 -212,7 +213,8 @@@ }); that.media.addEventListener( "timeupdate", function( event ) { + - var currentTime = this.currentTime, - previousTime = that.data.trackEvents.previousUpdateTime, - tracks = that.data.trackEvents, - tracksByEnd = tracks.byEnd, - tracksByStart = tracks.byStart; - - // Playbar advancing - if ( previousTime < currentTime ) { - - while ( tracksByEnd[ tracks.endIndex ] && tracksByEnd[ tracks.endIndex ].end <= currentTime ) { - // If plugin does not exist on this instance, remove it - if ( !tracksByEnd[ tracks.endIndex ]._natives || - ( !!Popcorn.registryByName[ tracksByEnd[ tracks.endIndex ]._natives.type ] || - !!that[ tracksByEnd[ tracks.endIndex ]._natives.type ] ) ) { - - if ( tracksByEnd[ tracks.endIndex ]._running === true ) { - tracksByEnd[ tracks.endIndex ]._running = false; - tracksByEnd[ tracks.endIndex ]._natives.end.call( that, event, tracksByEnd[ tracks.endIndex ] ); - } - tracks.endIndex++; - } else { - // remove track event - Popcorn.removeTrackEvent( that, tracksByEnd[ tracks.endIndex ]._id ); - return; - } - } - - while ( tracksByStart[ tracks.startIndex ] && tracksByStart[ tracks.startIndex ].start <= currentTime ) { - // If plugin does not exist on this instance, remove it - if ( !tracksByStart[ tracks.startIndex ]._natives || - ( !!Popcorn.registryByName[ tracksByStart[ tracks.startIndex ]._natives.type ] || - !!that[ tracksByStart[ tracks.startIndex ]._natives.type ] ) ) { - - if ( tracksByStart[ tracks.startIndex ].end > currentTime && - tracksByStart[ tracks.startIndex ]._running === false && - that.data.disabled.indexOf( tracksByStart[ tracks.startIndex ]._natives.type ) === -1 ) { - - tracksByStart[ tracks.startIndex ]._running = true; - tracksByStart[ tracks.startIndex ]._natives.start.call( that, event, tracksByStart[ tracks.startIndex ] ); - } - tracks.startIndex++; - } else { - // remove track event - Popcorn.removeTrackEvent( that, tracksByStart[ tracks.startIndex ]._id ); - return; - } - } - - // Playbar receding - } else if ( previousTime > currentTime ) { - - while ( tracksByStart[ tracks.startIndex ] && tracksByStart[ tracks.startIndex ].start > currentTime ) { - // if plugin does not exist on this instance, remove it - if ( !tracksByStart[ tracks.startIndex ]._natives || - ( !!Popcorn.registryByName[ tracksByStart[ tracks.startIndex ]._natives.type ] || - !!that[ tracksByStart[ tracks.startIndex ]._natives.type ] ) ) { - - if ( tracksByStart[ tracks.startIndex ]._running === true ) { - tracksByStart[ tracks.startIndex ]._running = false; - tracksByStart[ tracks.startIndex ]._natives.end.call( that, event, tracksByStart[ tracks.startIndex ] ); - } - tracks.startIndex--; - } else { - // remove track event - Popcorn.removeTrackEvent( that, tracksByStart[ tracks.startIndex ]._id ); - return; - } - } - - while ( tracksByEnd[ tracks.endIndex ] && tracksByEnd[ tracks.endIndex ].end > currentTime ) { - // if plugin does not exist on this instance, remove it - if ( !tracksByEnd[ tracks.endIndex ]._natives || - ( !!Popcorn.registryByName[ tracksByEnd[ tracks.endIndex ]._natives.type ] || - !!that[ tracksByEnd[ tracks.endIndex ]._natives.type ] ) ) { - - if ( tracksByEnd[ tracks.endIndex ].start <= currentTime && - tracksByEnd[ tracks.endIndex ]._running === false && - that.data.disabled.indexOf( tracksByEnd[ tracks.endIndex ]._natives.type ) === -1 ) { - - tracksByEnd[ tracks.endIndex ]._running = true; - tracksByEnd[ tracks.endIndex ]._natives.start.call( that, event, tracksByEnd[tracks.endIndex] ); - } - tracks.endIndex--; - } else { - // remove track event - Popcorn.removeTrackEvent( that, tracksByEnd[ tracks.endIndex ]._id ); - return; - } - } - } - - tracks.previousUpdateTime = currentTime; - + Popcorn.timeUpdate( that, event ); }, false ); } else { global.setTimeout(function() { @@@ -965,6 -871,91 +873,104 @@@ return obj.data.history[ obj.data.history.length - 1 ]; }; + Popcorn.timeUpdate = function( obj, event ) { + + var currentTime = obj.media.currentTime, + previousTime = obj.data.trackEvents.previousUpdateTime, + tracks = obj.data.trackEvents, + tracksByEnd = tracks.byEnd, + tracksByStart = tracks.byStart; + + // Playbar advancing + if ( previousTime < currentTime ) { + + while ( tracksByEnd[ tracks.endIndex ] && tracksByEnd[ tracks.endIndex ].end <= currentTime ) { + // If plugin does not exist on this instance, remove it - if ( !tracksByEnd[ tracks.endIndex ]._natives || !!obj[ tracksByEnd[ tracks.endIndex ]._natives.type ] ) { ++ if ( !tracksByEnd[ tracks.endIndex ]._natives || ++ ( !!Popcorn.registryByName[ tracksByEnd[ tracks.endIndex ]._natives.type ] || ++ !!obj[ tracksByEnd[ tracks.endIndex ]._natives.type ] ) ) { ++ + if ( tracksByEnd[ tracks.endIndex ]._running === true ) { + tracksByEnd[ tracks.endIndex ]._running = false; + tracksByEnd[ tracks.endIndex ]._natives.end.call( obj, event, tracksByEnd[ tracks.endIndex ] ); + } + tracks.endIndex++; + } else { + // remove track event + Popcorn.removeTrackEvent( obj, tracksByEnd[ tracks.endIndex ]._id ); + return; + } + } + + while ( tracksByStart[ tracks.startIndex ] && tracksByStart[ tracks.startIndex ].start <= currentTime ) { + // If plugin does not exist on this instance, remove it - if ( !tracksByStart[ tracks.startIndex ]._natives || !!obj[ tracksByStart[ tracks.startIndex ]._natives.type ] ) { ++ if ( !tracksByStart[ tracks.startIndex ]._natives || ++ ( !!Popcorn.registryByName[ tracksByStart[ tracks.startIndex ]._natives.type ] || ++ !!obj[ tracksByStart[ tracks.startIndex ]._natives.type ] ) ) { ++ + if ( tracksByStart[ tracks.startIndex ].end > currentTime && + tracksByStart[ tracks.startIndex ]._running === false && + obj.data.disabled.indexOf( tracksByStart[ tracks.startIndex ]._natives.type ) === -1 ) { + + tracksByStart[ tracks.startIndex ]._running = true; + tracksByStart[ tracks.startIndex ]._natives.start.call( obj, event, tracksByStart[ tracks.startIndex ] ); + } + tracks.startIndex++; + } else { + // remove track event + Popcorn.removeTrackEvent( obj, tracksByStart[ tracks.startIndex ]._id ); + return; + } - } ++ } ++ + // Playbar receding + } else if ( previousTime > currentTime ) { + + while ( tracksByStart[ tracks.startIndex ] && tracksByStart[ tracks.startIndex ].start > currentTime ) { + // if plugin does not exist on this instance, remove it - if ( !tracksByStart[ tracks.startIndex ]._natives || !!obj[ tracksByStart[ tracks.startIndex ]._natives.type ] ) { ++ if ( !tracksByStart[ tracks.startIndex ]._natives || ++ ( !!Popcorn.registryByName[ tracksByStart[ tracks.startIndex ]._natives.type ] || ++ !!obj[ tracksByStart[ tracks.startIndex ]._natives.type ] ) ) { ++ + if ( tracksByStart[ tracks.startIndex ]._running === true ) { + tracksByStart[ tracks.startIndex ]._running = false; + tracksByStart[ tracks.startIndex ]._natives.end.call( obj, event, tracksByStart[ tracks.startIndex ] ); + } + tracks.startIndex--; + } else { + // remove track event + Popcorn.removeTrackEvent( obj, tracksByStart[ tracks.startIndex ]._id ); + return; + } + } + + while ( tracksByEnd[ tracks.endIndex ] && tracksByEnd[ tracks.endIndex ].end > currentTime ) { + // if plugin does not exist on this instance, remove it - if ( !tracksByEnd[ tracks.endIndex ]._natives || !!obj[ tracksByEnd[ tracks.endIndex ]._natives.type ] ) { ++ if ( !tracksByEnd[ tracks.endIndex ]._natives || ++ ( !!Popcorn.registryByName[ tracksByEnd[ tracks.endIndex ]._natives.type ] || ++ !!obj[ tracksByEnd[ tracks.endIndex ]._natives.type ] ) ) { ++ + if ( tracksByEnd[ tracks.endIndex ].start <= currentTime && + tracksByEnd[ tracks.endIndex ]._running === false && + obj.data.disabled.indexOf( tracksByEnd[ tracks.endIndex ]._natives.type ) === -1 ) { + + tracksByEnd[ tracks.endIndex ]._running = true; + tracksByEnd[ tracks.endIndex ]._natives.start.call( obj, event, tracksByEnd[tracks.endIndex] ); + } + tracks.endIndex--; + } else { + // remove track event + Popcorn.removeTrackEvent( obj, tracksByEnd[ tracks.endIndex ]._id ); + return; - } ++ } + } + // time bar is not moving ( video is paused ) + } + + tracks.previousUpdateTime = currentTime; + + }; + // Map and Extend TrackEvent functions to all Popcorn instances Popcorn.extend( Popcorn.p, {