var WmMediaPlayer = Class.create(); WmMediaPlayer.prototype = { /** * initialize * * Creates a new instance of WmMediaPlayer * * @since initial * @param String file * @param Integer delay * @param Integer position * @param Integer volume * @param String template * @param String align * @return WmMediaPlayer **/ initialize: function(file, delay, position, volume, template, align) { this.fullscreen = false; this.initProxy(); this.initVars(file, delay, position, volume, template, align); }, /** * initProxy * * Creates a new instance of FlashProxy * * @since initial * @return void **/ initProxy: function() { this.uid = new Date().getTime(); this.flashProxy = new FlashProxy(this.uid, "/lib/mediaplayer/JavaScriptFlashGateway.swf"); window.FlashProxy = this; }, /** * initVars * * Adds the variables to the flashVars Object * * @since initial * @param String file * @param Integer delay * @param Integer position * @param Integer volume * @param String template * @param String align * @return void **/ initVars: function(file, delay, position, volume, template, align) { this.flashVars = { file : file, delay : delay, position : position, volume : volume, template : template, align :align } this.bgColor = "CCCCCC"; }, /** * setFlashVar * * Sets a variable with varName in the flashVars object * * @since initial * @param String varName * @param Mixed varValue * @return void **/ setFlashVar: function(varName, varValue) { if(varValue!=null) { this.flashVars[varName] = varValue; } }, /** * getFlashVars * * Returns a string with all the variables from the flashVars object * * @since initial * @return String vars **/ getFlashVars: function() { var vars = ""; for(property in this.flashVars) { if(this.flashVars[property] != null) { vars += "&" + property + "=" + this.flashVars[property]; } } return vars; }, /** * setSize * * Sets the size of the player div * * @since initial * @return void **/ setSize: function(width, height) { this.width = width; this.height = height; if(this.element) { Element.setStyle(this.element.id, {width : this.width + "px", height : this.height + "px"}); } }, /** * setInterface * * Sets a different interface template * * @since initial * @return void **/ setInterface: function(template, align, reload) { this.setFlashVar("template", template); this.setFlashVar("align", align); if(this.element) { this.flashProxy.call("setInterface", template, align, reload); } }, /** * addPlayButton * * Adds a play button in the middle of the mediaplayer * * @since Thu Jul 26 2007 * @param boolean init * @return void **/ addPlayButton: function(init) { if (init) { this.flashProxy.call("addPlayButton"); } else { this.addPlayButton.applyWithTimeout(this, 500, true); } }, /** * loadMedia * * Loads a file into the mediaplayer * * @since initial * @param string file * @param boolean play * @return void **/ loadMedia: function(file, play) { if (play) { play = 1; } else { play = 0; } this.flashProxy.call("loadMedia", file, play); }, playMedia: function() { this.flashProxy.call("playMedia"); }, pauseMedia: function() { this.flashProxy.call("pauseMedia"); }, stopMedia: function() { this.flashProxy.call("stopMedia"); }, setVolume:function(volume) { this.flashProxy.call("setVolume", volume); }, getVolume: function() { return this.flashVars['volume']; }, getPosition: function() { return this.flashVars['position']; }, toggleMute: function() { this.flashProxy.call("toggleMute"); }, isPlaying: function() { return this.flashVars['ISPLAYING']; }, isPaused: function() { return this.flashVars['ISPAUSED']; }, isStopped: function() { return this.flashVars['ISSTOPPED']; }, isMuted: function() { return this.flashVars['ISMUTED']; }, toggleScreen: function() { if (!this.fullscreen) { this.fullscreen = true; this.setSize(this.width * 2, this.height * 2); this.element.className = this.element.className + " pos_fullscreen"; } else { this.fullscreen = false; this.setSize(this.width / 2, this.height / 2); this.element.className = this.element.className.replace(/pos_fullscreen/i, ""); } }, write: function(element, wmode) { this.element = $(element); this.setSize(this.width, this.height); this.swfo = new SWFObject("/lib/mediaplayer/WmMediaPlayer.swf?lcId=" + this.uid + this.getFlashVars(), "swf_" + element, "100%", "100%", "8", this.bgColor); if (wmode) { this.swfo.addParam("wmode", "transparent"); } this.swfo.write(element); }, /** * This is the function that proxies function calls from Flash to JavaScript. * It is called implicitly. **/ callJS: function() { switch(arguments[0]) { case "toggleScreen": this.toggleScreen(); break; case "syncCall": syncObj = arguments[1]; this.syncCall(syncObj); break; case "errorCall": error = arguments[1]; this.errorCall(error); break; } }, syncCall: function(syncObj) { for(property in syncObj) { this.flashVars[property] = syncObj[property]; } }, errorCall: function(error) { alert(error); } }