var youtubeInit = function() {
+ var flashvars,
+ params,
+ attributes,
+ src;
+
// expose a callback to this scope, that is called from the global callback youtube calls
onYouTubePlayerReady[ container.id ] = function() {
}
};
- media.__defineSetter__( "currentTime", function( val ) {
-
- // make sure val is a number
- currentTime = seekTime = +val;
- seeking = true;
- media.dispatchEvent( "seeked" );
- media.dispatchEvent( "timeupdate" );
- youtubeObject.seekTo( currentTime );
- return currentTime;
- });
-
- media.__defineGetter__( "currentTime", function() {
+ Popcorn.player.defineProperty( media, "currentTime", {
+ set: function( val ) {
- return currentTime;
- });
+ if ( youtubeObject.isMuted() !== val ) {
- media.__defineSetter__( "muted", function( val ) {
+ if ( val ) {
- if ( youtubeObject.isMuted() !== val ) {
+ youtubeObject.mute();
+ } else {
- if ( val ) {
+ youtubeObject.unMute();
+ }
- youtubeObject.mute();
- } else {
-
- youtubeObject.unMute();
+ media.dispatchEvent( "volumechange" );
}
- media.dispatchEvent( "volumechange" );
- }
+ return youtubeObject.isMuted();
+ },
+ get: function() {
- return youtubeObject.isMuted();
+ return currentTime;
+ }
});
- media.__defineGetter__( "muted", function() {
+ Popcorn.player.defineProperty( media, "muted", {
+ set: function( val ) {
- return youtubeObject.isMuted();
- });
+ // make sure val is a number
+ currentTime = seekTime = +val;
+ seeking = true;
+ media.dispatchEvent( "seeked" );
+ media.dispatchEvent( "timeupdate" );
+ youtubeObject.seekTo( currentTime );
+ return currentTime;
+ },
+ get: function() {
- media.__defineSetter__( "volume", function( val ) {
+ return youtubeObject.isMuted();
+ }
+ });
- if ( youtubeObject.getVolume() !== val ) {
+ Popcorn.player.defineProperty( media, "volume", {
+ set: function( val ) {
- youtubeObject.setVolume( val );
- media.dispatchEvent( "volumechange" );
- }
+ if ( youtubeObject.getVolume() !== val ) {
- return youtubeObject.getVolume();
- });
+ youtubeObject.setVolume( val );
+ media.dispatchEvent( "volumechange" );
+ }
- media.__defineGetter__( "volume", function() {
+ return youtubeObject.getVolume();
+ },
+ get: function() {
- return youtubeObject.getVolume();
+ return youtubeObject.getVolume();
+ }
});
media.readyState = 4;
options.controls = +options.controls === 0 || +options.controls === 1 ? options.controls : 1;
options.annotations = +options.annotations === 1 || +options.annotations === 3 ? options.annotations : 1;
- var flashvars = {
+ flashvars = {
playerapiid: container.id,
controls: options.controls,
iv_load_policy: options.annotations
};
- swfobject.embedSWF( "http://www.youtube.com/e/" + /^.*[\/=](.{11})/.exec( media.src )[ 1 ] + "?enablejsapi=1&playerapiid=" + container.id + "&version=3",
+ params = {
+ wmode: "transparent",
+ allowScriptAccess: "always"
+ };
+
+ attributes = {
+ id: container.id
+ };
+
+ src = /^.*[\/=](.{11})/.exec( media.src )[ 1 ];
+
+ swfobject.embedSWF( "http://www.youtube.com/e/" + src + "?enablejsapi=1&playerapiid=" + container.id + "&version=3",
container.id, media.offsetWidth, media.offsetHeight, "8", null,
- flashvars, {wmode: "transparent", allowScriptAccess: "always"}, {id: container.id} );
+ flashvars, params, attributes );
};
if ( !window.swfobject ) {
basePlayer[ val ] = container[ val ];
} else if ( typeof container[ val ] === "function" ) {
- basePlayer[ val ] = ( function( value ) {
+ basePlayer[ val ] = (function( value ) {
return function() {
}( val ));
} else {
- basePlayer.__defineGetter__( val, ( function( value ) {
+ Popcorn.player.defineProperty( basePlayer, val, {
+ get: (function( value ) {
- return function() {
+ return function() {
- return container[ value ];
- };
- }( val )));
+ return container[ value ];
+ };
+ }( val )),
+ set: Popcorn.nop,
+ configurable: true
+ });
}
}
date = new Date() / 1000;
- if( !basePlayer.paused ) {
+ if ( !basePlayer.paused ) {
basePlayer.currentTime = basePlayer.currentTime + ( date - baselineTime );
basePlayer.dispatchEvent( "timeupdate" );
basePlayer.dispatchEvent( "pause" );
};
- basePlayer.__defineSetter__( "currentTime", function( val ) {
+ Popcorn.player.defineProperty( basePlayer, "currentTime", {
+ get: function() {
- // make sure val is a number
- currentTime = +val;
- basePlayer.dispatchEvent( "timeupdate" );
- return currentTime;
- });
-
- basePlayer.__defineGetter__( "currentTime", function() {
+ return currentTime;
+ },
+ set: function( val ) {
- return currentTime;
+ // make sure val is a number
+ currentTime = +val;
+ basePlayer.dispatchEvent( "timeupdate" );
+ return currentTime;
+ },
+ configurable: true
});
// Adds an event listener to the object
Popcorn[ name ] = Popcorn[ name ] || playerFn;
};
+ Popcorn.player.defineProperty = Object.defineProperty || function( object, description, options ) {
+
+ object.__defineGetter__( description, options.get || Popcorn.nop );
+ object.__defineSetter__( description, options.set || Popcorn.nop );
+ };
+
// Cache references to reused RegExps
var rparams = /\?/,
// XHR Setup object