From: Karim Hamidou Date: Wed, 9 Nov 2011 11:42:34 +0000 (+0100) Subject: added fragment update when the player is seeked X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=43a432bd0df2e72ec6520a155ec0d7124d635407;p=popcorn-js.git added fragment update when the player is seeked --- diff --git a/plugins/mediafragment/popcorn.mediafragment.js b/plugins/mediafragment/popcorn.mediafragment.js index 0f01e63..d2a3425 100644 --- a/plugins/mediafragment/popcorn.mediafragment.js +++ b/plugins/mediafragment/popcorn.mediafragment.js @@ -36,12 +36,14 @@ } } - - this.listen( 'loadedmetadata', advanceTime ); - this.listen("pause", function(data) { + var updateTime = function() { splitArr = window.location.href.split("#") history.replaceState({}, "", splitArr[0] + "#t=" + this.currentTime().toFixed(2)); - }); + }; + + this.listen( 'loadedmetadata', advanceTime ); + this.listen("pause", updateTime); + this.listen("seeked", updateTime); }, diff --git a/plugins/mediafragment/popcorn.mediafragment.unit.js b/plugins/mediafragment/popcorn.mediafragment.unit.js index 0fff2b3..659a273 100644 --- a/plugins/mediafragment/popcorn.mediafragment.unit.js +++ b/plugins/mediafragment/popcorn.mediafragment.unit.js @@ -1,7 +1,7 @@ -test( "Popcorn Footnote Plugin", function() { +test( "Popcorn Mediafragment Plugin", function() { var popped = Popcorn( "#video" ), - expects = 3, + expects = 4, count = 0; expect( expects ); @@ -34,7 +34,6 @@ test( "Popcorn Footnote Plugin", function() { popped.exec( 3, function() { var currstate = window.location.href.split("#t="); - console.log(currstate); var time = + currstate[1]; // popcorn's precision is limited to the second. @@ -42,9 +41,21 @@ test( "Popcorn Footnote Plugin", function() { plus(); popped.play(); + popped.currentTime(5); + }); + + popped.exec( 6, function() { + var currstate = window.location.href.split("#t="); + var time = + currstate[1]; + + console.log(time); + // popcorn's precision is limited to the second. + ok(time >= 5 && time <= 6, "correct time is set after seeking" ); + plus(); + }); - popped.exec( 4, function() { + popped.exec( 10, function() { // clear the address bar window.location.href = window.location.href.split("#t=")[0]; });