<commit_before>/*
 * The "kaltura player" embedPlayer interface for fallback h.264 and flv video format support
 */

// Called from the kdp.swf
function jsInterfaceReadyFunc() {
	return true;
}

mw.EmbedPlayerKplayer = {

	// Instance name:
	instanceOf : 'Kplayer',

	// List of supported features:
	supports : {
		'playHead' : true,
		'pause' : true,
		'stop' : true,
		'timeDisplay' : true,
		'volumeControl' : true,
		'overlays' : true,
		'fullscreen' : true
	},

	// Stores the current time as set from flash player
	flashCurrentTime : 0,

	/*
	 * Write the Embed html to the target
	 */
	doEmbedHTML : function() {
		var _this = this;

		mw.log("kPlayer:: embed src::" + _this.getSrc());
		var flashvars = {};
		flashvars.autoPlay = "true";
		var playerPath = mw.getMwEmbedPath() + 'modules/EmbedPlayer/binPlayers/kaltura-player';
		flashvars.entryId = mw.absoluteUrl( _this.getSrc() );

		// Use a relative url if the protocal is file://
		if (mw.parseUri(document.URL).protocol == 'file') {
			playerPath = mw.getRelativeMwEmbedPath() + 'modules/EmbedPlayer/binPlayers/kaltura-player';
			flashvars.entryId = _this.getSrc();
		}

		flashvars.debugMode = "true";
		flashvars.fileSystemMode = "true";
		flashvars.widgetId = "_7463";
		flashvars.partnerId = "7463";
		flashvars.pluginDomain = "kdp3/plugins/";
		flashvars.kml = "local";
		flashvars.kmlPath = playerPath + '/config.xml';
		flashvars.sourceType = "url";

		// flashvars.host = "www.kaltura.com";
		flashvars.externalInterfaceDisabled = 'false';
		flashvars.skinPath = playerPath + '/skin.swf';

		flashvars["full.skinPath"] = playerPath + '/LightDoodleskin.swf';

		var params = {};
		params.quality = "best";
		params.wmode = "opaque";
		params.allowfullscreen = "true";
		params.allowscriptaccess = "always";

		var attributes = {};
		attributes.id = this.pid;
		attributes.name = this.pid;

		mw.log(" KPlayer:: doEmbedHTML: about to add the pid container" );
		$j(this).html($j('<div />').attr('id', this.pid + '_container'));
		// Call swm dom loaded function:
		swfobject.callDomLoadFunctions();
		// Do the flash embedding with embedSWF
		swfobject.embedSWF(playerPath + "/kdp3.swf", this.pid + '_container',
				'100%', '100%', "10.0.0", playerPath + "/expressInstall.swf",
				flashvars, params, attributes);

		// Direct object embed
		/*
		 * $j( this ).html( '<object
		 * classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="780"
		 * height="420">'+ '<param name="movie" value="myContent.swf" />'+ '<!--[if
		 * !IE]>-->'+ '<object type="application/x-shockwave-flash"
		 * data="myContent.swf" width="780" height="420">'+ '<!--<![endif]-->'+ '<p>
		 * error with flash embed</p>' '<!--[if !IE]>-->'+ '</object>'+ '<!--<![endif]-->'+ '</object>' )
		 */

		setTimeout(function() {
			_this.postEmbedJS();
		}, 100);

		// Flash player loses its bindings once it changes sizes::
		$j(_this).bind('onOpenFullScreen', function() {
			_this.postEmbedJS();
		});
		$j(_this).bind('onCloseFullScreen', function() {
			_this.postEmbedJS();
		});
	},
	
	// The number of times we have tried to bind the player
	bindTryCount : 0,
	/**
	 * javascript run post player embedding
	 */
	postEmbedJS : function() {
		var _this = this;
		this.getPlayerElement();

		if (this.playerElement && this.playerElement.addJsListener) {
			var bindEventMap = {
				'doPause' : 'onPause',
				'doPlay' : 'onPlay',
				'durationChange' : 'onDurationChange',
				'playerPlayEnd' : 'onClipDone',
				'playerUpdatePlayhead' : 'onUpdatePlayhead',
				'bytesTotalChange' : 'onBytesTotalChange',
				'bytesDownloadedChange' : 'onBytesDownloadedChange'
			};
			
			$j.each( bindEventMap, function( bindName, localMethod ) {
				_this.bindPlayerFunction(bindName, localMethod);
			});
			this.bindTryCount = 0;
			// Start the monitor
			this.monitor();
		} else {
			this.bindTryCount++;
			// Keep trying to get the player element
			if( this.bindTryCount > 500 ){ // 5 seconds
				mw.log('Error:: KDP player never ready for bindings!');
				return ;
			}
			setTimeout(function() {
				_this.postEmbedJS();
			}, 10);
		}
	},

	/**
	 * Bind a Player Function,
	 * 
	 * Build a global callback to bind to "this" player instance:
	 * 
	 * @param {String}
	 *            flash binding name
	 * @param {String}
	 *            function callback name
	 */
	bindPlayerFunction : function(bindName, methodName) {
		// The kaltura kdp can only call a global function by given name
		var gKdpCallbackName = methodName + '_cb_' + this.id;

		// Create an anonymous function with local player scope
		var createGlobalCB = function(cName, embedPlayer) {
			window[ cName ] = function(data) {
				if ( embedPlayer._propagateEvents ) {
					embedPlayer[methodName](data);
				}
			};
		}(gKdpCallbackName, this);

		// Add the listener to the KDP flash player:
		this.playerElement.addJsListener(bindName, gKdpCallbackName);
	},

	/**
	 * on Pause callback from the kaltura flash player calls parent_pause to
	 * update the interface
	 */
	onPause : function() {
		this.parent_pause();
	},

	/**
	 * onPlay function callback from the kaltura flash player directly call the
	 * parent_play
	 */
	onPlay : function() {
		this.parent_play();
	},

	onDurationChange : function(data, id) {
		mw.log("KPlayer::onDurationChange: " + data.newValue);
		// update the duration:
		this.duration = data.newValue;
		$j(this).trigger('durationchange');
	},

	/**
	 * play method calls parent_play to update the interface
	 */
	play : function() {
		if (this.playerElement && this.playerElement.sendNotification) {
			this.playerElement.sendNotification('doPlay');
		}
		this.parent_play();
	},

	/**
	 * pause method calls parent_pause to update the interface
	 */
	pause : function() {
		if (this.playerElement && this.playerElement.sendNotification) {
			this.playerElement.sendNotification('doPause');
		}
		this.parent_pause();
	},
	/**
	 * switchPlaySrc switches the player source working around a few bugs in browsers
	 * 
	 * @param {string}
	 *            src Video url Source to switch to.
	 * @param {function}
	 *            switchCallback Function to call once the source has been switched<commit_msg>don't update the duration in url time encode mode<commit_after>/*
 * The "kaltura player" embedPlayer interface for fallback h.264 and flv video format support
 */

// Called from the kdp.swf
function jsInterfaceReadyFunc() {
	return true;
}

mw.EmbedPlayerKplayer = {

	// Instance name:
	instanceOf : 'Kplayer',

	// List of supported features:
	supports : {
		'playHead' : true,
		'pause' : true,
		'stop' : true,
		'timeDisplay' : true,
		'volumeControl' : true,
		'overlays' : true,
		'fullscreen' : true
	},

	// Stores the current time as set from flash player
	flashCurrentTime : 0,

	/*
	 * Write the Embed html to the target
	 */
	doEmbedHTML : function() {
		var _this = this;

		mw.log("kPlayer:: embed src::" + _this.getSrc());
		var flashvars = {};
		flashvars.autoPlay = "true";
		var playerPath = mw.getMwEmbedPath() + 'modules/EmbedPlayer/binPlayers/kaltura-player';
		flashvars.entryId = mw.absoluteUrl( _this.getSrc() );

		// Use a relative url if the protocal is file://
		if (mw.parseUri(document.URL).protocol == 'file') {
			playerPath = mw.getRelativeMwEmbedPath() + 'modules/EmbedPlayer/binPlayers/kaltura-player';
			flashvars.entryId = _this.getSrc();
		}

		flashvars.debugMode = "true";
		flashvars.fileSystemMode = "true";
		flashvars.widgetId = "_7463";
		flashvars.partnerId = "7463";
		flashvars.pluginDomain = "kdp3/plugins/";
		flashvars.kml = "local";
		flashvars.kmlPath = playerPath + '/config.xml';
		flashvars.sourceType = "url";

		// flashvars.host = "www.kaltura.com";
		flashvars.externalInterfaceDisabled = 'false';
		flashvars.skinPath = playerPath + '/skin.swf';

		flashvars["full.skinPath"] = playerPath + '/LightDoodleskin.swf';

		var params = {};
		params.quality = "best";
		params.wmode = "opaque";
		params.allowfullscreen = "true";
		params.allowscriptaccess = "always";

		var attributes = {};
		attributes.id = this.pid;
		attributes.name = this.pid;

		mw.log(" KPlayer:: doEmbedHTML: about to add the pid container" );
		$j(this).html($j('<div />').attr('id', this.pid + '_container'));
		// Call swm dom loaded function:
		swfobject.callDomLoadFunctions();
		// Do the flash embedding with embedSWF
		swfobject.embedSWF(playerPath + "/kdp3.swf", this.pid + '_container',
				'100%', '100%', "10.0.0", playerPath + "/expressInstall.swf",
				flashvars, params, attributes);

		// Direct object embed
		/*
		 * $j( this ).html( '<object
		 * classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="780"
		 * height="420">'+ '<param name="movie" value="myContent.swf" />'+ '<!--[if
		 * !IE]>-->'+ '<object type="application/x-shockwave-flash"
		 * data="myContent.swf" width="780" height="420">'+ '<!--<![endif]-->'+ '<p>
		 * error with flash embed</p>' '<!--[if !IE]>-->'+ '</object>'+ '<!--<![endif]-->'+ '</object>' )
		 */

		setTimeout(function() {
			_this.postEmbedJS();
		}, 100);

		// Flash player loses its bindings once it changes sizes::
		$j(_this).bind('onOpenFullScreen', function() {
			_this.postEmbedJS();
		});
		$j(_this).bind('onCloseFullScreen', function() {
			_this.postEmbedJS();
		});
	},
	
	// The number of times we have tried to bind the player
	bindTryCount : 0,
	/**
	 * javascript run post player embedding
	 */
	postEmbedJS : function() {
		var _this = this;
		this.getPlayerElement();

		if (this.playerElement && this.playerElement.addJsListener) {
			var bindEventMap = {
				'doPause' : 'onPause',
				'doPlay' : 'onPlay',
				'durationChange' : 'onDurationChange',
				'playerPlayEnd' : 'onClipDone',
				'playerUpdatePlayhead' : 'onUpdatePlayhead',
				'bytesTotalChange' : 'onBytesTotalChange',
				'bytesDownloadedChange' : 'onBytesDownloadedChange'
			};
			
			$j.each( bindEventMap, function( bindName, localMethod ) {
				_this.bindPlayerFunction(bindName, localMethod);
			});
			this.bindTryCount = 0;
			// Start the monitor
			this.monitor();
		} else {
			this.bindTryCount++;
			// Keep trying to get the player element
			if( this.bindTryCount > 500 ){ // 5 seconds
				mw.log('Error:: KDP player never ready for bindings!');
				return ;
			}
			setTimeout(function() {
				_this.postEmbedJS();
			}, 10);
		}
	},

	/**
	 * Bind a Player Function,
	 * 
	 * Build a global callback to bind to "this" player instance:
	 * 
	 * @param {String}
	 *            flash binding name
	 * @param {String}
	 *            function callback name
	 */
	bindPlayerFunction : function(bindName, methodName) {
		// The kaltura kdp can only call a global function by given name
		var gKdpCallbackName = methodName + '_cb_' + this.id;

		// Create an anonymous function with local player scope
		var createGlobalCB = function(cName, embedPlayer) {
			window[ cName ] = function(data) {
				if ( embedPlayer._propagateEvents ) {
					embedPlayer[methodName](data);
				}
			};
		}(gKdpCallbackName, this);

		// Add the listener to the KDP flash player:
		this.playerElement.addJsListener(bindName, gKdpCallbackName);
	},

	/**
	 * on Pause callback from the kaltura flash player calls parent_pause to
	 * update the interface
	 */
	onPause : function() {
		this.parent_pause();
	},

	/**
	 * onPlay function callback from the kaltura flash player directly call the
	 * parent_play
	 */
	onPlay : function() {
		this.parent_play();
	},

	onDurationChange : function(data, id) {
		mw.log("KPlayer::onDurationChange: " + data.newValue);
		// update the duration ( only if not in url time encoding mode:
		if( !this.supportsURLTimeEncoding() ){
			this.duration = data.newValue;
			$j(this).trigger('durationchange');
		}
	},

	/**
	 * play method calls parent_play to update the interface
	 */
	play : function() {
		if (this.playerElement && this.playerElement.sendNotification) {
			this.playerElement.sendNotification('doPlay');
		}
		this.parent_play();
	},

	/**
	 * pause method calls parent_pause to update the interface
	 */
	pause : function() {
		if (this.playerElement && this.playerElement.sendNotification) {
			this.playerElement.sendNotification('doPause');
		}
		this.parent_pause();
	},
	/**
	 * switchPlaySrc switches the player source working around a few bugs in browsers
	 * 
	 * @param {string}
	 *            src Video url Source to switch to.
	 * @param {function}
	 *            switchCallback Function to call once the source has been switched
{'fraction_non_alphanumeric': 0.14844064791683456, 'fraction_numerical': 0.010959787251188654, 'mean_word_length': 3.488245931283906, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4813865', 'n_tokens_mistral': 4605, 'n_tokens_neox': 3955, 'n_words': 999}