From a9bec94a34c6145df006f780279032282032f26d Mon Sep 17 00:00:00 2001 From: Jeremy Banks Date: Tue, 12 Jun 2012 15:45:45 -0400 Subject: [PATCH] Throw an Error if popcorn.duration() is NaN after ready. (#57) --- js/setup.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/js/setup.js b/js/setup.js index 7133186..3a4e069 100755 --- a/js/setup.js +++ b/js/setup.js @@ -208,16 +208,23 @@ addEventListener( "DOMContentLoaded", function() { // Initialization to take place after media (and Butter)? is ready. function initAfterMediaReady () { + // HTTP/1.0 servers can cause audio elements to break silently. We want them to break loudly. var duration = popcorn.duration(), originalTime = popcorn.currentTime(), targetTime = 0; + // .duration breaks in Firefox: + if ( isNaN( duration ) ) { + throw new Error( "popcorn.duration() is NaN.") + } + if ( originalTime === targetTime ) { targetTime += popcorn.duration() / 2; } popcorn.currentTime( targetTime ); + // .currentTime breaks in Chrome: if ( popcorn.currentTime() === originalTime ) { throw new Error( "Calling popcorn.currentTime(x) did not affect the value of popcorn.currentTime()." ); }