]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
[#729] Adds play(n)/pause(n) shorthands to currentTime(n).play()/pause() Includes...
authorRick Waldron <waldron.rick@gmail.com>
Wed, 21 Sep 2011 16:02:12 +0000 (12:02 -0400)
committerRick Waldron <waldron.rick@gmail.com>
Wed, 21 Sep 2011 16:02:12 +0000 (12:02 -0400)
popcorn.js
test/popcorn.unit.js

index e2c7320a73229cfaa39255e2c7fe59c740cf6e82..b0e9e0a6aebcda86a9722c781689d9031871310c 100644 (file)
         ret[ name ] = function( arg ) {
 
           if ( typeof this.media[ name ] === "function" ) {
+
+            // Support for shorthanded play(n)/pause(n) jump to currentTime
+            // If arg is not null or undefined and called by one of the
+            // allowed shorthandable methods, then set the currentTime
+                                               // Supports time as seconds or SMPTE
+            if ( arg != null && /play|pause/.test( name ) ) {
+              this.media.currentTime = Popcorn.util.toSeconds( arg );
+            }
+
             this.media[ name ]();
 
             return this;
index 6dfff8f4996c8d8ecd5150f130ac1e8564ec6b5d..61b9a86d54f7d89287cb93e3f5cb24b91f889ff7 100644 (file)
@@ -601,6 +601,46 @@ test("mute", function() {
 
 });
 
+test("play(n) as shorthand to currentTime(n).play()", function() {
+
+  var $pop = Popcorn( "#video" ),
+    expects = 2,
+    count = 0,
+    fired = 0;
+
+  expect( expects );
+
+  function plus() {
+    if ( ++count == expects ) {
+      start();
+    }
+  }
+
+  stop( 1000 );
+
+  function poll() {
+
+    if ( $pop.media.readyState >= 2 ) {
+      // this should trigger immediately
+
+      $pop.play( 10 ).pause();
+
+      equal( Math.round($pop.currentTime()), 10, "play(n) sets currentTime to 10" );
+      plus();
+
+      $pop.pause( 5 );
+
+      equal( Math.round($pop.currentTime()), 5, "pause(n) sets currentTime to 5" );
+      plus();
+
+    } else {
+      setTimeout( poll, 10 );
+    }
+  }
+
+  poll();
+});
+
 
 module("Popcorn Static Methods");