currentTime = 0,
seekTime = 0,
seeking = false,
- dataLoaded = false,
// state code for volume changed polling
volumeChanged = false,
media.paused = false;
media.dispatchEvent( "play" );
- if ( dataLoaded ) {
-
- media.dispatchEvent( "loadeddata" );
- dataLoaded = false;
- }
-
media.dispatchEvent( "playing" );
timeupdate();
youtubeObject.playVideo();
media.readyState = 4;
media.dispatchEvent( "load" );
- dataLoaded = true;
media.duration = youtubeObject.getDuration();
media.dispatchEvent( "durationchange" );
volumeupdate();
- if ( !media.paused ) {
-
- media.play();
- }
-
- media.paused && media.dispatchEvent( "loadeddata" );
+ media.dispatchEvent( "loadeddata" );
};
options.controls = +options.controls === 0 || +options.controls === 1 ? options.controls : 1;
var date = new Date() / 1000,
baselineTime = date,
currentTime = 0,
+ volume = 1,
+ muted = false,
events = {},
// The container div of the resource
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 ) {
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 );
// 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;