flash actionscript:
Does anyone know a good tutorial for a Multiple MP3 player? I can make a player that plays one Mp3, but cant seem to figure out how to alter the code to allow for multiple sound objects.
create an array with the identifier names of the songs that are in your library. (set the identifier name of the song by right clicking on the song in the library, choosing linkage, check the export for actionscript and export in first frame checkboxes, then give it a unique name in the identifier text box) Here's an array with three songs: <!--Begin actionscript--> songArray = ["soulLoop", "grooveLoop", "fastBeat"] //the items in the array are the indentifiear names mySound = new Sound( ); //set a variable to the Sound object soulButton.onRelease = function ( ) { stopAllSounds();//stops any other song that may be playing whichOne = songArray[0]; mySound.attachSound(whichOne); mySound.start(0); mySound.onSoundComplete = function( ) { mySound.start(0); //the line above and this line replays the song when it finishes its first loop } } grooveButton.onRelease = function ( ) { stopAllSounds( ); whichOne = songArray[1]; mySound.attachSound(whichOne); mySound.start(0); mySound.onSoundComplete = function( ) { mySound.start(0); } } beatButton.onRelease = function ( ) { stopAllSounds( ); whichOne = songArray[2]; mySound.attachSound(whichOne); mySound.start(0); mySound.onSoundComplete = function( ) { mySound.start(0); } } <!--End actionscript--> FYI soulButton, grooveButton, and beatButton are the names of the buttons on stage.
what if you want to load the mp3s dynamically? The problem I'm having is with my pause/play buttons. Since I only have 1 soundobject and each song is loaded into the same sound object, the position property doesn't reset between songs and thus my pause function (var pauseTime = mySound.position) works incorrectly. Any ideas? Rob
for play/pause, can you make use of the code / logic in this file ? http://www.jackleaman.co.uk/mp3_php_jukebox.html a good tutorial on the sound object -
I tried to attach an fla file that should help you, but for some reason I can't get it to attach to this reply. If you post your email address I will email it to you. Instead of using the attachSound method that you'll see in the script (once I've emailed the file to you), use loadSound("http://serverpath/file.mp3", streaming?) Streaming needs to equal true or false. If it's false, I believe you will need to attach the sound object variable to the beginning of loadSound (ie: mySound = new Sound ( )' mySound.loadSound("http://serverpath/file.mp3", false) Otherwise it will just look like this: loadSound("http://serverpath/file.mp3", true) Use this in place of where you see the attachSound method in my fla file. And of course you'll no longer need the array or the variable that grabs the identifier name out of the array. Hope this helps!! Brenda
mySound.loadSound can be either "event" (does not play until the file is completely loaded) or "streaming" (plays as soon as enough data loads to begin playing). true = streaming false = event if you use false (event), you need to tell Flash to start playing that sound after it loads, so the script would be mySound.loadSound("the sound's URL" , false); mySound.onLoad = function() { mySound.start(0, 1); } cheers, Rob
Don't see what you're looking for? Try a search.
|