MOWJWPlayersList = new Array(); MOWJWPlayer = Class.create(); MOWJWPlayer.prototype = { initialize: function(DivID) { // FlashVars da passare al player this.FlashVars = $H({ autostart: false, // true/false bufferlength: 0.1, displayclick: 'play', logo: undefined, mute: false, quality: true, repeat: 'always', // none, list, always shuffle: false, stretching: 'fill', // uniform, fill, exactfit, none volume: 80 // 0-100 }); this.FlashVars = this.FlashVars.merge($H(arguments[1] || {})); this.Parameters = $H({ width: 400, height: 20, useEqualizer: false, equalizerDiv: '', eqIcon: 3, allowfullscreen: 'true' }); this.Parameters = this.Parameters.merge($H(arguments[2] || {})); this.doDebug = false; this.DebugLayer = null; this.Name = this.RandomID(); eval(this.Name+'=this'); this.SWFObject = null; this.Loaded = false; this.PlayerID = 'JWPlayer_'+MOWJWPlayersList.length; this.thePlayer = null; this.Playing = this.FlashVars.get('autostart'); this.theEqualizer; // Memorizza la classe presente nell'array globale dei player (serve per la funzione che avvisa del caricamento avvenuto) MOWJWPlayersList[MOWJWPlayersList.length] = this; //alert(MOWJWPlayersList.inspect()); this.DivID = DivID; this.SavedVolume = this.FlashVars.get('volume'); }, //------------------------------------------------------------------------------------------------------- load: function() { this.SWFObject = new SWFObject('JWPlayer/player.swf',this.PlayerID,this.Parameters.get('width'),this.Parameters.get('height'),'9','#f5f5f5'); this.SWFObject.addParam('allowfullscreen', this.Parameters.get('allowfullscreen')); this.SWFObject.addParam('allowscriptaccess','always'); this.SWFObject.addParam('wmode','opaque'); this.SWFObject.addParam('flashvars',this.FlashVars.toQueryString()); this.SWFObject.write(this.DivID); if (this.Parameters.get('useEqualizer')) { tmpid = this.RandomID(); OnOff = this.FlashVars.get('autostart') ? 'on' : 'off'; $(this.Parameters.get('equalizerDiv')).innerHTML = ''; this.theEqualizer = $(tmpid); } }, setLoaded: function() { this.thePlayer = $(this.PlayerID); this.Loaded = true; this.setListeners(); //alert('Loaded'); }, /** * Impostazione delle funzioni di callback */ setListeners: function() { this.thePlayer.addControllerListener('VOLUME', this.Name+'.updateVolume'); this.thePlayer.addControllerListener('PLAY', this.Name+'.updateState'); this.thePlayer.addControllerListener('ITEM', this.Name+'.updateItem'); }, /** * Funzione di Callback chiamata dal player quando viene cambiato il volume */ updateVolume: function(obj) { this.FlashVars.set({volume: obj.percentage}); }, updateState: function(obj) { this.Playing = obj.state; }, updateItem: function(obj) { this.Playing = true; }, setVolume: function(percentage) { this.thePlayer.sendEvent('VOLUME',percentage); }, AnimatedSwitch: function() { if (this.Playing) { this.FadeOut(); this.theEqualizer.src = 'JWPlayer/images/equalizer.'+ this.Parameters.get('eqIcon') +'.off.gif'; } else { this.theEqualizer.src = 'JWPlayer/images/equalizer.'+ this.Parameters.get('eqIcon') +'.on.gif'; this.Play(); } }, //--- Comands ------------------------------------------------------------------------------------------- //------------------------------------------------------------------------------------------------------- crossTest: function() { this.FadeOut(); this.thePlayer.sendEvent('LOAD',{file:"http://stream8-7.jamendo.com/21279/mp31/06%20-%20Sax%20Moryson%20-%20Good%20Morning.mp3",title:"Sax & Moryson : Lovely World Dies - Good Morning"}); this.PauseMS(500); this.FadeIn(); }, Play: function() { this.thePlayer.sendEvent('PLAY','true'); }, Stop: function() { this.thePlayer.sendEvent('PLAY','false'); }, FadeOut: function(duration) { duration = duration || 2000; this.SavedVolume = this.FlashVars.get('volume'); Pause = duration / this.FlashVars.get('volume'); for (i = this.FlashVars.get('volume'); i > 0; i--) { this.setVolume(i); this.PauseMS(Pause); } this.Stop(); this.setVolume(this.SavedVolume); }, FadeIn: function(duration) { duration = duration || 2000; this.setVolume(0); this.Play(); Pause = duration / this.SavedVolume; for (i = 0; i < this.SavedVolume; i++) { this.setVolume(i); this.PauseMS(Pause); } }, sendEvent: function(p1, p2) { this.thePlayer.sendEvent(p1, p2); }, getPlaylist: function() { return this.thePlayer.getPlaylist(); }, //--- UTILITY ------------------------------------------------------------------------------------------- //------------------------------------------------------------------------------------------------------- enableDebug: function() { this.DebugLayer = new Element('div', {style:'position:absolute;overflow-y:auto;top:0px;left:0px;height:600px;width:300px;display:none;background-color:#000;color:#FFF;'}); Play = new Element('div', {style:'padding:4px;position:absolute;top:10px;left:310px;height:30;width:80px;display:none;background-color:#000;color:#FFF;', onClick:this.Name+'.Play();'}); Stop = new Element('div', {style:'padding:4px;position:absolute;top:50px;left:310px;height:30;width:80px;display:none;background-color:#000;color:#FFF;', onClick:this.Name+'.Stop();'}); new Element.insert(this.holderDiv, {after: this.DebugLayer}); this.DebugLayer.innerHTML = 'MOWSLide::DebugMode
'; new Effect.Appear(this.DebugLayer, {from:0.0, to:0.7, duration:1}); new Element.insert(this.holderDiv, {after: Play}); Play.innerHTML = 'Play'; new Effect.Appear(Play, {from:0.0, to:0.7, duration:1}); new Element.insert(this.holderDiv, {after: Stop}); Stop.innerHTML = 'Stop'; new Effect.Appear(Stop, {from:0.0, to:0.7, duration:1}); this.doDebug = true; }, debug: function(text) { if (this.doDebug) this.DebugLayer.innerHTML += text; }, findRealPosition: function(obj) { var curleft = curtop = 0; if (obj.offsetParent) { curleft = obj.offsetLeft curtop = obj.offsetTop while (obj = obj.offsetParent) { curleft += obj.offsetLeft curtop += obj.offsetTop } } return {'x': curleft, 'y': curtop}; }, RandomID: function() { var sRnd = ''; var sChrs = 'abcdefghijklmnoqrstuwxyz'; for (var i=0; i <= 16; i++) { var randomPoz = Math.floor(Math.random() * sChrs.length); sRnd += sChrs.substring(randomPoz,randomPoz+1); } return sRnd; }, PauseMS: function(millis) { var date = new Date(); var curDate = null; do { curDate = new Date(); } while(curDate-date < millis); } } playerReady = function(obj) { var id = obj['id']; var version = obj['version']; var client = obj['client']; // Tramite espressione regolare verifica se l'id del JWPlayer corrisponde ad una class MOWJWPlayr instanziata // Nel caso avvisala che pronta var myregexp = /([0-9]+)/; var match = myregexp.exec(obj['id']); if (match != null && match.length > 1) { //alert('the videoplayer '+id+' has been instantiated ('+ match[1] +')'); MOWJWPlayersList[match[1]].setLoaded(); } }