PDA

View Full Version : Looping multiple mp3 streams


jtrory
08-07-2005, 09:44 PM
First, let me commend all of you on a great forum full of valuable resources. I wouldn't have gotten as far as I have without the forums here. I am a Flash newbie with experience in web design using good ol' HTML and Java. ActionScripts are still fairly new to me.

Okay, to my question. Here is what I have and what I want to do:

Currently, I have one streaming .mp3 that loops from the beginning:

s = new Sound();
s.loadSound("http://www.freelands.net/lull/bdg/mus_MainTheme.mp3",true);
s.onSoundComplete = function() {
s.start(0, 99);
}

This .mp3 is controlled by two buttons, Pause and Play.

Pause:
on(release){
cue = Math.round(s.position/1000);
s.stop();
}

Play:
on(release){
s.start(cue,1);
}

Everything works fine. But here's where I'm stuck.

I want to add multiple .mp3's that play in order and then loop back to the first .mp3. I don't want the user to control this, it is background music, not an MP3 player. I don't even know what the ActionScript would be for adding multiple .mp3's. More to the point, I haven't the slightest idea how to adjust my buttons so that they know which .mp3 they're supposed to be pausing and playing.

So far I have tried simply adding in URL's, but that doesn't seem to work. I have tried making an .m3u playlist file that I use to replace the .mp3 file, but Flash doesn't recognize .m3u files, so that doesn't work either.

I have searched your forums, I have looked on http://www.kennybellew.com/tutorial/ and numerous other websites, but nothing really addresses this specific issue. Any assistance would be greatly appreciated.

Navarone
08-08-2005, 09:15 PM
I am not sure this would work, but on the first SoundComplete, create a new sound object, and load the next mp3, then on that mp3's SoundComplete fuction, do the same thing again. I didn't test this. I don't know if you have to create a new sound object each time, but it's a start.

There is probabbly away to create an array and loop through your sounds. KeneyBellew, didn't have anything..eh?


s = new Sound();
s.loadSound("http://www.freelands.net/lull/bdg/mus_MainTheme.mp3", true);
s.onSoundComplete = function() {
t = new Sound();
t.loadSound("http://www.freelands.net/lull/bdg/somthingelse.mp3", true);
t.onSoundComplete = function() {
u = new Sound();
u.loadSound("http://www.freelands.net/lull/bdg/somthingelse.mp3", true);
u.onSoundComplete = function() {
//
};
};
};

jtrory
08-08-2005, 11:03 PM
Well you see the problem with that is that my buttons only fuction with the SoundObject "s". I had tried something very similar and it worked as far as streaming multiple .mp3's was concerned, but once the second .mp3 started playing, my buttons were looking for "s" and "s" wasn't playing anymore, another SoundObject was. If I repeat the same code within the buttons for different SoundObjects, the buttons just get confused.

However, it suddenly occurred to me that there is an incredibly simple, quick fix to this problem, and it has nothing to do with ActionScript. I realized all I needed to do was c&p the .mp3's onto the ends of each other and save it as one long .mp3. Since the file is streaming, the size doesn't matter too much because the file plays as it buffers. Then I set the one .mp3 to loop and TADAA!

Seems to work like a charm. I'm not sure how this will affect bandwidth, the .mp3 as it is now is 22MB which I think I will have to scale down. But it did the job.

Navarone
08-08-2005, 11:05 PM
Glad you figured it out. :)