diff -r c35da6f48eef -r b3140ffed377 src/js/popcorn.js --- a/src/js/popcorn.js Thu Oct 13 17:14:07 2011 +0200 +++ b/src/js/popcorn.js Mon Oct 17 10:29:01 2011 +0200 @@ -1313,9 +1313,16 @@ // Returns wrapped plugin function function safeTry( fn, pluginName ) { return function() { + + // When Popcorn.plugin.debug is true, do not suppress errors + if ( Popcorn.plugin.debug ) { + return fn.apply( this, arguments ); + } + try { return fn.apply( this, arguments ); } catch ( ex ) { + // Push plugin function errors into logging queue Popcorn.plugin.errors.push({ plugin: pluginName, @@ -1525,6 +1532,8 @@ var date = new Date() / 1000, baselineTime = date, currentTime = 0, + volume = 1, + muted = false, events = {}, // The container div of the resource @@ -1613,6 +1622,36 @@ configurable: true }); + Popcorn.player.defineProperty( basePlayer, "volume", { + get: function() { + + return volume; + }, + set: function( val ) { + + // make sure val is a number + volume = +val; + basePlayer.dispatchEvent( "volumechange" ); + return volume; + }, + configurable: true + }); + + Popcorn.player.defineProperty( basePlayer, "muted", { + get: function() { + + return muted; + }, + set: function( val ) { + + // make sure val is a number + muted = +val; + basePlayer.dispatchEvent( "volumechange" ); + return muted; + }, + configurable: true + }); + // Adds an event listener to the object basePlayer.addEventListener = function( evtName, fn ) { @@ -1659,10 +1698,6 @@ basePlayer.paused = true; basePlayer.ended = 0; - // basePlayer has no concept of sound - basePlayer.volume = 1; - basePlayer.muted = false; - if ( player._setup ) { player._setup.call( basePlayer, options ); @@ -1670,9 +1705,27 @@ // there is no setup, which means there is nothing to load basePlayer.readyState = 4; - basePlayer.dispatchEvent( 'load' ); + basePlayer.dispatchEvent( "load" ); + basePlayer.dispatchEvent( "loadeddata" ); } + // when a custom player is loaded, load basePlayer state into custom player + basePlayer.addEventListener( "load", function() { + + // if a player is not ready before currentTime is called, this will set it after it is ready + basePlayer.currentTime = currentTime; + + // same as above with volume and muted + basePlayer.volume = volume; + basePlayer.muted = muted; + }); + + basePlayer.addEventListener( "loadeddata", function() { + + // if play was called before player ready, start playing video + !basePlayer.paused && basePlayer.play(); + }); + popcorn = new Popcorn.p.init( basePlayer, options ); return popcorn; @@ -1972,9 +2025,28 @@ // alias for exec function Popcorn.p.cue = Popcorn.p.exec; + function getItems() { + + var item, + list = []; + + if ( Object.keys ) { + list = Object.keys( Popcorn.p ); + } else { + + for ( item in Popcorn.p ) { + if ( hasOwn.call( Popcorn.p, item ) ) { + list.push( item ); + } + } + } + + return list.join( "," ).toLowerCase().split( ","); + } + // Protected API methods Popcorn.protect = { - natives: Object.keys( Popcorn.p ).join( "," ).toLowerCase().split( "," ) + natives: getItems() }; // Exposes Popcorn to global context