From 08e9d837aba705b43c39be9c3c7ec0e3d80f5684 Mon Sep 17 00:00:00 2001 From: Rick Waldron Date: Wed, 13 Jun 2012 14:27:28 -0500 Subject: [PATCH] Fix smpte support regression, add test. --- popcorn.js | 16 +++++++++++++++- test/popcorn.unit.js | 33 +++++++++++++++++++++------------ 2 files changed, 36 insertions(+), 13 deletions(-) diff --git a/popcorn.js b/popcorn.js index 5eef6e1a..c0699feb 100644 --- a/popcorn.js +++ b/popcorn.js @@ -547,7 +547,21 @@ // Attach an event to a single point in time exec: function( id, time, fn ) { var length = arguments.length, - trackEvent; + trackEvent, sec; + + // Check if first could possibly be a SMPTE string + // p.cue( "smpte string", fn ); + // try/catch avoid awful throw in Popcorn.util.toSeconds + // TODO: Get rid of that, replace with NaN return? + try { + sec = Popcorn.util.toSeconds( id ); + } catch ( e ) {} + + // If it can be converted into a number then + // it's safe to assume that the string was SMPTE + if ( typeof sec === "number" ) { + id = sec; + } // Shift arguments based on use case // diff --git a/test/popcorn.unit.js b/test/popcorn.unit.js index f6d8f671..7eecb4c5 100644 --- a/test/popcorn.unit.js +++ b/test/popcorn.unit.js @@ -894,13 +894,14 @@ test( "roundTime", function() { test( "exec", function() { - QUnit.reset(); - var popped = Popcorn( "#video" ), - expects = 2, + expects = 3, count = 0, - hasLooped = false, - loop = 0; + loop = 0, + flags = { + looped: false, + smpte: false + }; expect( expects + 1 ); @@ -909,7 +910,7 @@ test( "exec", function() { setTimeout(function() { - equal( loop, expects, "cue callback repeat check, only called twice" ); + equal( loop, 2, "cue callback repeat check, only called twice" ); Popcorn.removePlugin( popped, "cue" ); popped.destroy(); start(); @@ -919,17 +920,25 @@ test( "exec", function() { stop(); + // Supports SMPTE + popped.cue( "00:00:04", function() { + if ( !flags.smpte ) { + flags.smpte = true; + ok( true, "cue supports SMPTE" ); + plus(); + } + }); + + popped.cue( 4, function() { ok( loop < 2, "cue callback fired " + ++loop ); plus(); - if ( !hasLooped ) { - - popped.currentTime( 3 ).play(); - - hasLooped = true; + if ( !flags.looped ) { + flags.looped = true; + popped.play( 3 ); } - }).currentTime( 3 ).play(); + }).play( 3 ); }); test( "cue: alias of exec", function() {