Skip to content

Commit

Permalink
Throw an Error if popcorn.duration() is NaN after ready. (dseif#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyBanks committed Jun 12, 2012
1 parent 9a86c2a commit a9bec94
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions js/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()." );
}
Expand Down

0 comments on commit a9bec94

Please sign in to comment.