]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
[#280] Bugfixes in popcorn core for duration, mute implementation in player
authorstevenaw <sweerdenburg@gmail.com>
Tue, 8 Mar 2011 05:08:43 +0000 (00:08 -0500)
committerstevenaw <sweerdenburg@gmail.com>
Tue, 8 Mar 2011 05:08:43 +0000 (00:08 -0500)
players/vimeo/popcorn.vimeo.html
players/vimeo/popcorn.vimeo.js
players/vimeo/popcorn.vimeo.unit.js
popcorn.js

index 507f22379aca1ae9f92ab07db46990ef3c762828..20b5e51be3a6cfeac7e34e6a7eab8495a62126be 100644 (file)
@@ -63,7 +63,7 @@
                 
                 // Mute
                 document.getElementById( "btnMute" ).addEventListener( "click", function() {
-                  player.volume( 0 );
+                  player.mute();
                 }, false);
                 
                 // Hook into player events
index 2ac1b29979f16b01052e99d2b212bc1565c3e32c..0e6864183c6bb5e957cb24ba7e3a1a5b7475db60 100644 (file)
@@ -83,6 +83,7 @@
   *   volume ( get only, set by calling setVolume() )
   *
   *   load() function
+  *   mute() function
   *
   * Unsupported media attributes:
   *   buffered
       // Better to store them here than on the DOM
       this.objVars = {
         paused: true,
-        duration: -1,
+        duration: Number.NaN,
         ended: 0,
-        currentTime: -1,
+        currentTime: Number.NaN,
         volume: 1,
         loop: 0,
         initialTime: 0,
     duration: function() {
       return this.objVars.duration;
     },
+    mute: function() {
+      if ( !this.muted() ) {
+        this.objVars.oldVol = this.objVars.volume;
+        this.volume( 0 );
+      } else {
+        this.volume( this.objVars.oldVol );
+      }
+    },
     muted: function() {
       return this.objVars.volume === 0;
     },
index 471e0fd0b64d6a09324953abbeaae4aad4a7c0ec..036fd3cba95126589634849ab5a3c7d29de08bc9 100644 (file)
@@ -20,7 +20,7 @@ test("Popcorn Vimeo Plugin", function () {
   }
   
   var popped = Popcorn.vimeo( "player_1", "http://vimeo.com/11127501" ),
-      expects = 21,
+      expects = 23,
       playCount = 0,
       pauseCount = 0,
       count = 0,
@@ -48,11 +48,21 @@ test("Popcorn Vimeo Plugin", function () {
               ok( popped.video.muted(), "Muted set when player volume 0" );
               plus();
               
-              popped.volume( 1 );
+              popped.volume( 0.333 );
             } else if ( timesCalled === 2 ) {
               ok( !popped.video.muted(), "Unmuted when volume not 0" );
               plus();
               
+              popped.mute();
+            } else if ( timesCalled === 3 ) {
+              ok( popped.video.muted(), "Mute mutes when volume is non-zero" );
+              plus();
+              
+              popped.mute();
+            } else if ( timesCalled === 4 ) {
+              equals( popped.volume(), 0.333, "Mute unmutes to last volume" );
+              plus();
+              
               popped.exec( 4, function() {
                 popped.video.unload();
               });
@@ -110,7 +120,7 @@ test("Popcorn Vimeo Plugin", function () {
   
   expect( expects );
   
-  stop( 20000 );
+  stop( /* 20000 */ );
   
   ok( "vimeo" in Popcorn, "Vimeo is a method of Popcorn" );
   plus();
index fc98f3e51005425904a4c1054a7986463091ed56..5a916504581dc26629912fd52f0ca91db941f9fe 100644 (file)
       }
 
 
-      matches = rIdExp.exec( entity );
-
-      if ( matches.length && matches[2]  ) {
-        elem = document.getElementById(matches[2]);
-      }
+      if ( (typeof entity) == "string" ) {
+        matches = rIdExp.exec( entity );
 
+        if ( matches.length && matches[2]  ) {
+          elem = document.getElementById(matches[2]);
+        }
 
-      this.video = elem ? elem : null;
+        this.video = elem ? elem : null;
+      } else if ( entity instanceof Object ) {
+        this.video = entity;
+      }
 
       this.data = {
         history: [],
           // adding padding to the front and end of the arrays
           // this is so we do not fall off either end
 
-          var duration = that.video.duration;
+          var duration = typeof that.video.duration === "function" ? that.video.duration() : that.video.duration;
           // Check for no duration info (NaN)
           var videoDurationPlus = duration != duration ? Number.MAX_VALUE : duration + 1;
 
                 tracksByEnd    = tracks.byEnd,
                 tracksByStart  = tracks.byStart;
 
+
+            if (typeof this.currentTime === "function") {
+              currentTime = this.currentTime();
+            }
+
             // Playbar advancing
             if ( previousTime < currentTime ) {
 
         }
       };
 
-      isReady( this );
+      if ( this.video ) {
+        isReady( this );
+      }
 
       return this;
     }
 
       //  Build methods, store in object that is returned and passed to extend
       Popcorn.forEach( methods.split(/\s+/g), function( name ) {
-          
-        ret[ name ] = function( arg ) {
 
-          if ( typeof this.video[name] === "function" ) {
-            // Looad, play, pause, mute do not reeturn a value when nothing is passed to them
-            if ( /load|play|pause|mute/.test( name ) || arg !== false && arg !== null && typeof arg !== "undefined" ) {
-            
-              this.video[ name ]();
-              return this;
-              
-            }
-            
-            return this.video[ name ]( arg );
-          }
+        ret[ name ] = function( arg ) {
 
+          var isFunc = typeof this.video[name] === "function";
 
-          if ( arg !== false && arg !== null && typeof arg !== "undefined" ) {
+          if ( /load|play|pause|mute/.test( name ) || ( arg !== false && arg !== null && typeof arg !== "undefined" ) ) {
 
-            this.video[ name ] = arg;
+            if ( isFunc ) {
+              this.video[ name ]( arg );
+            } else {
+              this.video[ name ] = arg;
+            }
 
             return this;
           }
 
+          if ( isFunc ) {
+            return this.video[ name ]();
+          }
+
           return this.video[ name ];
         };
       });
 
 
       settings.ajax.open( settings.type, settings.url, settings.async );
-      settings.ajax.send( settings.data = null ? null : settings.data );
+      settings.ajax.send( settings.data || null );
 
       return Popcorn.xhr.httpData( settings );
     }
   }, false );
 
 })(window, window.document);
+