From: ScottDowne Date: Thu, 29 Sep 2011 15:40:00 +0000 (-0400) Subject: [#743] basePlayer caching state for custom players X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=90295a89c67686fd04b5a57370158139466e1092;p=popcorn-js.git [#743] basePlayer caching state for custom players --- diff --git a/players/youtube/popcorn.youtube.js b/players/youtube/popcorn.youtube.js index 28aa2eb..3af9f2e 100755 --- a/players/youtube/popcorn.youtube.js +++ b/players/youtube/popcorn.youtube.js @@ -14,7 +14,6 @@ Popcorn.player( "youtube", { currentTime = 0, seekTime = 0, seeking = false, - dataLoaded = false, // state code for volume changed polling volumeChanged = false, @@ -100,12 +99,6 @@ Popcorn.player( "youtube", { media.paused = false; media.dispatchEvent( "play" ); - if ( dataLoaded ) { - - media.dispatchEvent( "loadeddata" ); - dataLoaded = false; - } - media.dispatchEvent( "playing" ); timeupdate(); youtubeObject.playVideo(); @@ -183,17 +176,11 @@ Popcorn.player( "youtube", { media.readyState = 4; media.dispatchEvent( "load" ); - dataLoaded = true; media.duration = youtubeObject.getDuration(); media.dispatchEvent( "durationchange" ); volumeupdate(); - if ( !media.paused ) { - - media.play(); - } - - media.paused && media.dispatchEvent( "loadeddata" ); + media.dispatchEvent( "loadeddata" ); }; options.controls = +options.controls === 0 || +options.controls === 1 ? options.controls : 1; diff --git a/players/youtube/popcorn.youtube.unit.js b/players/youtube/popcorn.youtube.unit.js index e93b553..d5e9b89 100644 --- a/players/youtube/popcorn.youtube.unit.js +++ b/players/youtube/popcorn.youtube.unit.js @@ -162,7 +162,12 @@ test("Update Timer", function () { } }); - p2.currentTime(3).play(); + p2.exec( 3, function() { + + p2.play(); + }); + + p2.currentTime(3); }); diff --git a/popcorn.js b/popcorn.js index d94c49d..9ead0d7 100644 --- a/popcorn.js +++ b/popcorn.js @@ -1491,6 +1491,8 @@ var date = new Date() / 1000, baselineTime = date, currentTime = 0, + volume = 1, + muted = false, events = {}, // The container div of the resource @@ -1579,6 +1581,36 @@ configurable: true }); + Popcorn.player.defineProperty( basePlayer, "volume", { + get: function() { + + return volume; + }, + set: function( val ) { + + // make sure val is a number + volume = +val; + basePlayer.dispatchEvent( "volumechange" ); + return volume; + }, + configurable: true + }); + + Popcorn.player.defineProperty( basePlayer, "muted", { + get: function() { + + return muted; + }, + set: function( val ) { + + // make sure val is a number + muted = +val; + basePlayer.dispatchEvent( "volumechange" ); + return muted; + }, + configurable: true + }); + // Adds an event listener to the object basePlayer.addEventListener = function( evtName, fn ) { @@ -1625,10 +1657,6 @@ basePlayer.paused = true; basePlayer.ended = 0; - // basePlayer has no concept of sound - basePlayer.volume = 1; - basePlayer.muted = false; - if ( player._setup ) { player._setup.call( basePlayer, options ); @@ -1636,9 +1664,27 @@ // there is no setup, which means there is nothing to load basePlayer.readyState = 4; - basePlayer.dispatchEvent( 'load' ); + basePlayer.dispatchEvent( "load" ); + basePlayer.dispatchEvent( "loadeddata" ); } + // when a custom player is loaded, load basePlayer state into custom player + basePlayer.addEventListener( "load", function() { + + // if a player is not ready before currentTime is called, this will set it after it is ready + basePlayer.currentTime = currentTime; + + // same as above with volume and muted + basePlayer.volume = volume; + basePlayer.muted = muted; + }); + + basePlayer.addEventListener( "loadeddata", function() { + + // if play was called before player ready, start playing video + !basePlayer.paused && basePlayer.play(); + }); + popcorn = new Popcorn.p.init( basePlayer, options ); return popcorn;