// flash MP3 player actionscrip. works with an xml playlist and a flash movie containing // 4 labeled buttons: // play_btn_1 // pause_btn_1 // stop_btn_1 // next_btn_1 // now some fun slider stuff // a text field is generated to display the Song title from the ID3 tag. if the ID3 tag is // not avalable the file path/name are displayed instead. i dont know about itunes and ID3 tags... // // please note this is all action script 2.0 // resources: Fash MX 2004 Action Script BIBLE, by Robert Reinhardt and Joey Lott (c) 2004 // the online flash resources we helpfull in concept, but they all refer to specific action script 3.0 code... var whoami = this; stop(); // ------------------------------------------------------------declare variables var playhead_1 : Number; var myvol_1 : Number; var stitle_1 : String; var songPlaying_1 : Boolean; var song_1 : Sound = new Sound (); var sa_1 : Array = new Array(); // make new array sa (song array) var si_1 : Number; // song index var xml : XML = new XML(); //------------------------------------------------------------initialize variables_1 playhead_1 = 0; // init play head possition to the start of the song songPlaying_1 = false; // init song playing state to false so that the play button can start playing si_1 = 0; //initialize song index to play first song //song.loadSound("audio/fsound1.mp3", true); //song.stop(); myvol_1 = song_1.getVolume(); // get volume, hopefully this will be set by the time this is called... song_1.setVolume(myvol_1); //set volume to default level //------------------------------------------------------- PROCESS XML xml.ignoreWhite = true; xml.load ("songs.xml"); // your local file songs.xml xml.onLoad = function(){ trace("xml loaded"); var nodes : Array = this.firstChild.childNodes; // first label, sum of sublabels under first label of xml text trace("XMLfilehas this many nodes: " +nodes.length); for (var i = 0; i < nodes.length; i++){ // loop from zero to sum of sublabels sa_1.push(nodes[i].attributes.url); // store the ULR strings in the song array trace("booyah "+ whoami + nodes[i].attributes.url + " "); } _root.songsLoadedLetsGo(); } // -------------------------------------------------------------end XML // -----------------------------------------------------------------make some label spaces: this.createTextField("tLabel0", this.getNextHighestDepth(), 10, 35, 250, 55); tLabel0.text = "TITLE: "; // this one wont change... tLabel0.autoSize ="left"; // put the text on the left... tLabel0.selectable = false; // dont select the text (or let anyone else select it) tLabel0.background = true; // the background behind the text... tLabel0.backgroundColor = 0x111111; // dark grey tLabel0.textColor = 0xCCCCCC;// light grey this.createTextField("tLabel1", this.getNextHighestDepth(), 10, 35, 250, 45); tLabel1.text = "hello world"; // i have always enjoyed saying that... tLabel1.autoSize ="left"; // put the text on the left there tLabel1.selectable = false; // dont select the text... tLabel1.background = true; // the background behind the text tLabel1.backgroundColor = 0x111111; // dark grey tLabel1.textColor = 0xCCCCCC;// light grey this.createTextField("tLabel2", this.getNextHighestDepth(), 10, 50, 250, 55); tLabel2.text = " "; // space for volume display here. tLabel2.autoSize ="left"; // put the text on the left there tLabel2.selectable = false; // dont select the text... tLabel2.background = true; // the background behind the text tLabel2.backgroundColor = 0x111111; // dark grey tLabel2.textColor = 0xCCCCCC;// light grey // ------------------------------------------------------------------- PLAYBACK FUNCTIONS // loop songs until next song is called song_1.onSoundComplete= songLoop_1; function songLoop_1():Void{ songPlaying_1 = false; // reset song playing flag so that song can be re-started songPlay_1(); } //---------------------------------------------------------play function_1 function songPlay_1():Void{ if(songPlaying_1 != true){ //play only if song is not already playing song_1.start(playhead_1, 0); // play i think i should be able to loop here but it seems to not work... songPlaying_1 = false; // hehe. broke the old code to allow for re-triggering //------------------------lets see if we can display the song name stitle_1 = song_1.id3.songname; if (stitle_1 == undefined) { //tLabel1.text = "i have no idea... lets make up a name togeter" // display snarky text instead of undefined message tLabel1.text = sa_1[si_1]; // display fileName or path or URL if id3s are not working... } else{ tLabel1.text =stitle_1; // it would be swell if the ID3 tags worked, they would show text here. }// end else }// end if songPlaying }// end playSong //---------------------------------------pause function_1 function songPause_1():Void{ playhead_1 = song_1.position / 1000; // convert poisition in milis to playhead offset in seconds song_1.stop(); songPlaying_1 = false; // set playing state trace("PlayHead at " + playhead_1); } //---------------------------------------stop function_1 function songStop_1():Void{ song_1.stop(); // stop the mp3 playback songPlaying_1 = false; playhead_1 = 0; tLabel1.text = " "; // this makes a big blank text field } //---------------------------------------Play Next Song Function_1 function playNextSong_1():Void{ playhead_1 = 0; // reset the playhead possition (just incase pause has saved us some other starting point songPlaying_1 = false; // set that state... // increment song index, or reset if at maximum if( si_1 == sa_1.length - 1){ si_1 = 0; } else{ si_1++;} // now that we know which song index we will use, lets load and play the song myvol_1 = song_1.getVolume(); // get previous volume setting song_1.loadSound(sa_1[si_1], true); // laod ( filename, streaming) song_1.setVolume(myvol_1); // set volume setting after song is loaded. songPlay_1(); // play it } //------------------------------------------------------------------------------------INIT sound /* when there is only one sound object the xfader doesn't funciton properly. this requires that we start both sounds at loadtime to insure that the xfade has two places to send volume controls */ function startSound_1():Void{ myvol_1 = song_1.getVolume(); // get previous volume setting song_1.loadSound(sa_1[si_1], true); // laod ( filename, streaming) song_1.setVolume(myvol_1); // set volume setting after song is loaded. songStop_1(); } //-----------------------------------------------------------------------------Volume Controls // are now in another script /// ------------------------------------------------------------------button calls // these are the labeled buttons that are needed in the swf... this.play_btn_1.onPress = songPlay_1; this.pause_btn_1.onPress = songPause_1; this.stop_btn_1.onPress = songStop_1; this.next_btn_1.onPress = playNextSong_1;