]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
[#743] basePlayer caching state for custom players
authorScottDowne <sdowne@learn.senecac.on.ca>
Thu, 29 Sep 2011 15:40:00 +0000 (11:40 -0400)
committerScottDowne <sdowne@learn.senecac.on.ca>
Thu, 29 Sep 2011 15:40:00 +0000 (11:40 -0400)
players/youtube/popcorn.youtube.js
players/youtube/popcorn.youtube.unit.js
popcorn.js

index 28aa2eb7f5c80e1c438121c5953904a258107869..3af9f2ef633e9ac49c3b8978916fdaadeca69c45 100755 (executable)
@@ -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;
index e93b55352715ed1bc44f11466184e7eb828c33e7..d5e9b89d5d743bc965c14f1a286669a08c135fd3 100644 (file)
@@ -162,7 +162,12 @@ test("Update Timer", function () {
     }
   });
 
-  p2.currentTime(3).play();
+  p2.exec( 3, function() {
+
+    p2.play();
+  });
+
+  p2.currentTime(3);
 
 });
 
index d94c49d41977ab6865df1329cb9d52dd230fd79d..9ead0d7167147e0c6aa423f16e149544bd8c7556 100644 (file)
       var date = new Date() / 1000,
           baselineTime = date,
           currentTime = 0,
+          volume = 1,
+          muted = false,
           events = {},
 
           // The container div of the resource
         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 ) {
 
       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 );
 
         // 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;