/////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////// // /////// // Wimpy JS /////// // Version 2.0 /////// // /////// // by Mike Gieson /////// // /////// // Available at http://www.wimpyplayer.com /////// // 2002-2006 plaino /////// // /////// /////////////////////////////////////////////////////////////// // // This product includes software developed by Macromedia, Inc. // // Macromedia(r) Flash(r) JavaScript Integration Kit // Portions noted as part of the JavaScript Integration Kit // are Copyright (c) 2005 Macromedia, inc. All rights reserved. // http://www.macromedia.com/go/flashjavascript/ // // Macromedia(r) Flash(r) JavaScript Integration Kit Created by: // // Christian Cantrell // http://weblogs.macromedia.com/cantrell/ // mailto:cantrell@macromedia.com // // Mike Chambers // http://weblogs.macromedia.com/mesh/ // mailto:mesh@macromedia.com // // Macromedia // ///////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////// //////////// //////////// //////////// OPTIONS //////////// //////////// //////////// ///////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////// // // Refer to the "readme_wimpy_mp3_js.html" file for details. // wimpySwf = "wimpy.swf"; theWidth = 168; theHeight = 60; theBkgdColor = "FFFFFF"; // // You can use an external wimpyConfigs.xml file to set the remainder of the options wimpyConfigFile = ""; // ... or set them here: // wimpySkin = "/minivan_style/min_rad.xml"; trackPlays = ""; voteScript = ""; defaultImage = "example.jpg"; startPlayingOnload = "yes"; shuffleOnLoad = ""; randomOnLoad = ""; displayDownloadButton = ""; startOnTrack = "no"; autoAdvance = "no"; popUpHelp = ""; scrollInfoDisplay = ""; infoDisplayTime = ""; bufferAudio = ""; theVolume = ""; limitPlaytime = ""; startupLogo = "/images/logo.jpg"; // ///////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////// //////////// //////////// //////////// Advanced Usage (experts only!) //////////// //////////// //////////// ///////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////// // // // js_wimpy_returnOnComplete = ""; // // HINT: Add one slash to the line below (the line with the * ) to uncomment this entire section. // /* // // The variable "js_wimpy_returnOnComplete" is sent into Flash to // establish a the name of the function that Wimpy should "ping" after // successfully receiveing a JavaScript command. // // Set js_wimpy_returnOnComplete to the function name that Flash // will call upon successfully completing a previous JavaScript request. // // Example: // js_wimpy_returnOnComplete = "myReturnFunction"; // // In this example, Wimpy will ping the function myReturnFunction. // function myReturnFunction(myReturnArg){ // Wimpy will return either a "string" or "array" (object) in the // myReturnArg argument. For most Wimyp javascript commands, Wimpy will // not return any meaningful data, so Wimpy will only return the name of // the function that it received so that you can verify that the javascript // function actually made it to Wimpy and so you can differentiate between // each response that Wimpy returns. // As mentioned earlier, most of the Wimpy Javascript functions don't return // anything meaningfull, hense Wimpy only returns a "string" identifying the // name of the function is was requested to perform. Functions such as // wimpy_play, wimpy_stop, wimpy_gotoAndPlay (among others) only return the // name of the function as a string. // Whereas with functions that return information that you can use, Wimpy // will return an "array" (object), where the first index of the array (0) is // the name of the function that Wimpy was asked to perform. The remaining // indexes in the array contain information about the requested track. All of // the information that is available for the specified track is returned. Do // for example, if you are using an XML playlist, and you ahve decided to // include additioan for each in the playlist, all of the tags // sent in to Wimpy through the XML playlist will be returned. // Used during testing (it's a little annoying, but a little bit more // trustworthy than re-writing
tags. // alert ("Wimpy returned: " + myReturnArg); // Here we check to see what kind of data-type is returned // (either an array object or a string) if(typeof(myReturnArg) == "object"){ // Put the returned array into a new variable so we can modify it var returnedArray = myReturnArg; // Remove the first element of the array and put it into a new // variable so we can determine which action Wimpyjust performed. var myAction = returnedArray.shift(); // Here we can fork out to different methods based on the name of the action // that just occured. For the sake of this example, all of the returned function // use do the same thing (printReturnedData), but for your needs, you can fork // out to different functions. if(myAction == "wimpy_getTrackInfo"){ printReturnedData(myAction, returnedArray); } else if (myAction == "wimpy_returnPlaylistItem"){ printReturnedData(myAction, returnedArray); } else if (myAction == "wimpy_trackDone"){ printReturnedData(myAction, returnedArray); } else if (myAction == "wimpy_trackStarted"){ printReturnedData(myAction, returnedArray); } // If the returned argument is not an array (i.e. its a string or a number), and you would // like something to occur based on the name of the function that Wimpy has just prossessed // you can do so here. // For this example, we've set up a system to load and play a pre-defined list of files // (See "Example A Code" below). This example is set up to show you how you can leverage // the "call and response" behaviour between Wimpy and Javascript when using the // js_wimpy_returnOnComplete feature, so that you can monitor and interact between // your web page, the user and Wimpy. // When the link entitled "Review next track (Example A)" is clicked, the wimpy_clearPlaylist // function is invoked, which will clear the playlist. Once Wimpy returns the name of the // function (indicating that the wimpy_clearPlaylist function is complete), a new track is // loaded into the player using the loadAndPlay function. } else { if(myReturnArg == "wimpy_clearPlaylist"){ alert ("The next item will now load and play"); wimpy_loadAndPlay( myPlaylist[currentTrack][0], myPlaylist[currentTrack][1], myPlaylist[currentTrack][2], myPlaylist[currentTrack][3], myPlaylist[currentTrack][4] ); currentTrack++ } } } function printReturnedData(theActionName, theDataArray){ var returnedData = ""; returnedData += "
Action initiated: "+theActionName+"

"; for(i=0;i"; } writit(returnedData,"trackInfo"); } function writit(text,id){ if (document.getElementById) { x = document.getElementById(id); x.innerHTML = ''; x.innerHTML = text; } else if (document.all) { x = document.all[id]; x.innerHTML = text; } else if (document.layers) { x = document.layers[id]; text2 = '

' + text + '

'; x.document.open(); x.document.write(text2); x.document.close(); } } // Example A Code currentTrack = 0; myPlaylist = new Array(); myPlaylist[0] = new Array('example1.mp3', '', 'Track 1', '', ''); myPlaylist[1] = new Array('example2.mp3', '', 'Track 2', '', ''); myPlaylist[2] = new Array('example3.mp3', '', 'Track 3', '', ''); myPlaylist[3] = new Array('example4.mp3', '', 'Track 4', '', ''); // //*/ // // ///////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////// //////////// //////////// //////////// Do not edit below here //////////// //////////// //////////// ///////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////// randNum = (Math.round((Math.random()*1000000)+1)); function makeWimpyPlayer(thePlaylist){ thePlaylist = thePlaylist || ""; var newlineChar = "\n"; var bkgdColor; var tptBkgd_param; var writePlaylist; var altString; var queryString; var js2wimpy_param; var js2wimpy_embed; var flashCode = ''; var flashVersion = "6,0,47,0"; var myConfigs = "wimpySkin,trackPlays,voteScript,defaultImage,startPlayingOnload,shuffleOnLoad,randomOnLoad,displayDownloadButton,startOnTrack,autoAdvance,popUpHelp,scrollInfoDisplay,infoDisplayTime,bufferAudio,theVolume,js_wimpy_returnOnComplete,limitPlaytime,startupLogo"; var AmyConfigs = myConfigs.split(","); var AprintConfigs = Array(); for(i=0;i 4){ altString = '&wimpyConfigs='+wimpyConfigFile; } else { altString = "&"+myConfigs; } // myuid = new Date().getTime(); wimpyProxy = new FlashProxy(myuid, wimpySwf); js2wimpy_param = ''+newlineChar; js2wimpy_embed = 'flashvars="lcId='+myuid+'" '; // queryString = wimpySwf +'?x='+randNum+altString+writePlaylist; // flashCode += ''+newlineChar; flashCode += ''+newlineChar; flashCode += ''+newlineChar; flashCode += ''+newlineChar; flashCode += ''+newlineChar; flashCode += ''+newlineChar; flashCode += ''+newlineChar; flashCode += ''+newlineChar; flashCode += tptBkgd_param; flashCode += js2wimpy_param; flashCode += ''+newlineChar; document.write(flashCode); // Uncomment to trouble shoot the HTML code. //document.write('
'); } function getExtension(theFilename){ return unescape(theFilename).split("/").pop().split(".").pop().toLowerCase(); } function wimpy_play(){ wimpyProxy.call('js_wimpy_play'); } function wimpy_stop(){ wimpyProxy.call('js_wimpy_stop'); } function wimpy_pause(){ wimpyProxy.call('js_wimpy_pause'); } function wimpy_next(){ wimpyProxy.call('js_wimpy_next'); } function wimpy_prev(){ wimpyProxy.call('js_wimpy_prev'); } function wimpy_gotoTrack(trackNumber){ wimpyProxy.call('js_wimpy_gotoTrack', trackNumber); } function wimpy_clearPlaylist(){ wimpyProxy.call('js_wimpy_clearPlaylist'); } function wimpy_appendPlaylist(trackOrPlaylist, theFile, theArtist, theTitle, theHyperlink, theGraphic){ wimpyProxy.call('js_wimpy_appendPlaylist', trackOrPlaylist, theFile, theArtist, theTitle, theHyperlink, theGraphic); } function wimpy_loadAndPlay(theFile, theArtist, theTitle, theHyperlink, theGraphic){ wimpyProxy.call('js_wimpy_loadAndPlay', theFile, theArtist, theTitle, theHyperlink, theGraphic); } function wimpy_appendMultipleTracks(theFileList, theGroupTitle, theHyperlink, theGraphic){ wimpyProxy.call('js_wimpy_appendMultipleTracks', theFileList, theGroupTitle, theHyperlink, theGraphic); } // These functions return an array, and require you to use js_wimpy_returnOnComplete. function wimpy_getTrackInfo(){ wimpyProxy.call('js_wimpy_getTrackInfo'); } function wimpy_returnPlaylistItem(trackNumber){ wimpyProxy.call('js_wimpy_returnPlaylistItem', trackNumber); } ///////////////////////////////////////////////////////// ///////////////////////////////////////////////////////// /* The following code is part of the Flash / JavaScript Integration Kit: http://www.macromedia.com/go/flashjavascript/ */ function Exception(name, message){ if (name) this.name = name; if (message) this.message = message; } Exception.prototype.setName = function(name){ this.name = name; } Exception.prototype.getName = function(){ return this.name; } Exception.prototype.setMessage = function(msg){ this.message = msg; } Exception.prototype.getMessage = function(){ return this.message; } function FlashProxy(uid, proxySwfName){ this.uid = uid; this.proxySwfName = proxySwfName; this.flashSerializer = new FlashSerializer(false); } FlashProxy.prototype.call = function(){ if (arguments.length == 0) { throw new Exception("Flash Proxy Exception", "The first argument should be the function name followed by any number of additional arguments."); } var qs = 'lcId=' + escape(this.uid) + '&functionName=' + escape(arguments[0]); if (arguments.length > 1) { var justArgs = new Array(); for (var i = 1; i < arguments.length; ++i) { justArgs.push(arguments[i]); } qs += ('&' + this.flashSerializer.serialize(justArgs)); } var divName = '_flash_proxy_' + this.uid; if(!document.getElementById(divName)) { var newTarget = document.createElement("div"); newTarget.id = divName; document.body.appendChild(newTarget); } var target = document.getElementById(divName); var ft = new FlashTag(this.proxySwfName, 1, 1); ft.setVersion('6,0,65,0'); ft.setFlashvars(qs); target.innerHTML = ft.toString(); //document.getElementById("textarea").value = divName; } FlashProxy.callJS = function(){ var functionToCall = eval(arguments[0]); var argArray = new Array(); for (var i = 1; i < arguments.length; ++i) { argArray.push(arguments[i]); } functionToCall.apply(functionToCall, argArray); } function FlashSerializer(useCdata){ this.useCdata = useCdata; } FlashSerializer.prototype.serialize = function(args){ var qs = new String(); for (var i = 0; i < args.length; ++i) { switch(typeof(args[i])) { case 'undefined': qs += 't'+(i)+'=undf'; break; case 'string': qs += 't'+(i)+'=str&d'+(i)+'='+escape(args[i]); break; case 'number': qs += 't'+(i)+'=num&d'+(i)+'='+escape(args[i]); break; case 'boolean': qs += 't'+(i)+'=bool&d'+(i)+'='+escape(args[i]); break; case 'object': if (args[i] == null) { qs += 't'+(i)+'=null'; } else if (args[i] instanceof Date) { qs += 't'+(i)+'=date&d'+(i)+'='+escape(args[i].getTime()); } else // array or object { try { qs += 't'+(i)+'=xser&d'+(i)+'='+escape(this._serializeXML(args[i])); } catch (exception) { throw new Exception("FlashSerializationException", "The following error occurred during complex object serialization: " + exception.getMessage()); } } break; default: throw new Exception("FlashSerializationException", "You can only serialize strings, numbers, booleans, dates, objects, arrays, nulls, and undefined."); } if (i != (args.length - 1)) { qs += '&'; } } return qs; } FlashSerializer.prototype._serializeXML = function(obj){ var doc = new Object(); doc.xml = ''; this._serializeNode(obj, doc, null); doc.xml += ''; return doc.xml; } FlashSerializer.prototype._serializeNode = function(obj, doc, name){ switch(typeof(obj)) { case 'undefined': doc.xml += ''; break; case 'string': doc.xml += ''+this._escapeXml(obj)+''; break; case 'number': doc.xml += ''+obj+''; break; case 'boolean': doc.xml += ''; break; case 'object': if (obj == null) { doc.xml += ''; } else if (obj instanceof Date) { doc.xml += ''+obj.getTime()+''; } else if (obj instanceof Array) { doc.xml += ''; for (var i = 0; i < obj.length; ++i) { this._serializeNode(obj[i], doc, null); } doc.xml += ''; } else { doc.xml += ''; for (var n in obj) { if (typeof(obj[n]) == 'function') continue; this._serializeNode(obj[n], doc, n); } doc.xml += ''; } break; default: throw new Exception("FlashSerializationException", "You can only serialize strings, numbers, booleans, objects, dates, arrays, nulls and undefined"); break; } } FlashSerializer.prototype._addName= function(name){ if (name != null) { return ' name="'+name+'"'; } return ''; } FlashSerializer.prototype._escapeXml = function(str){ if (this.useCdata) return ''; else return str.replace(/&/g,'&').replace(/'; flashTag += ''; flashTag += ''; flashTag += ''; if (this.flashVars != null) { flashTag += ''; } flashTag += ''; } else { flashTag += '