PDA

View Full Version : Seamless looping MP3 sound (or silent gap glitch)?


cybereality
02-03-2008, 10:13 PM
I am trying to have an mp3 sound play in the background as a seamless loop. I am using the Sound and SoundChannel class and I can play the sound fine. The problem I have is that when the sound loops there is a small gap between the end of the loop and the start at the beginning. I did a search I didn't find any obvious solution. Is there something I'm missing here, this seems like a very basic feature.

From what I understand this issue has to do with the encoding of the mp3 file. So what do I need to do in order to export an mp3 file without the silent gap? Is there any workaround in flash to get around with without editing the audio files? What about support for other audio formats aside from mp3? Any help will be greatly appreciated.

atomic
02-03-2008, 10:29 PM
The problem was the same with AS2.0... Don't see why it'd be different for AS3.0...
Looping soundObjects have never looped as seamlessly as simple timeline looping sounds. On some of them (again on AS2.0), playing with the second offset parameter would help to shorthen the gap, but it wasn't very steady...

cybereality
02-03-2008, 11:05 PM
What has changed is that you were able to use wav sounds for music previously, and it appears AS3.0 only supports mp3 audio. I was hoping there was something new to AS3.0 that would help with looping sounds, but I guess not. So is the only way to use the timeline for placing sounds? There must be some workaround with code.

Mazoonist
02-03-2008, 11:49 PM
MP3 files are the only kind that can be loaded from an external file. You can still import WAV files to the library, give them a class name, and play them with Actionscript (without placing them on the timeline).

cybereality
02-04-2008, 12:08 AM
MP3 files are the only kind that can be loaded from an external file. You can still import WAV files to the library, give them a class name, and play them with Actionscript (without placing them on the timeline).

Thanks so much, that is what I was looking for. Its kinda funny actually because I just figured it out (doing a google search) like 5 minutes before you posted. I'm very surprised that this solution wasn't widely posted before on this forum, I noticed a lot of other people had struggled with the same problem.

Heres the code if anyone is interested:

var soundLoop:Sound = new LoopingSound();
soundLoop.play(0, 99);

Just import your audio file (wav/aif) into the library and give it a linkage class of "LoopingSound" (for the above example, it could be anything you like) by default it should extend the "Sound" class which is what you want. Then you can call it from script as above and it loops correctly.

Mazoonist
02-04-2008, 01:43 AM
Exactly!

By the way....

If your sound file does have a gap of silence (one that isn't flash's fault), you can edit it out with Audacity. This free program came on a disk with a USB turntable I got, but you can also get it as a free download from: http://audacity.sourceforge.net/. Consult the help files to learn how to export MP3, as it involves downloading a dll file, which isn't a big deal either. After playing with the program and the turntable for awhile, and recording a few vinyl albums, I realized that you can also use the program to easily load and edit any MP3 files, and other sound file types, too, including WAV.

Find and highlight the gap of silence, and press the delete key. Easy! Then, save (export as MP3) the file under a different name to preserve the original.

cybereality
02-04-2008, 03:42 AM
By the way....

If your sound file does have a gap of silence (one that isn't flash's fault), you can edit it out with Audacity.

Oh yes, me and Audacity are old friends ;). Thanks for the tip though.

cybereality
02-25-2008, 07:32 AM
It turns out that the audio file did need editing with audacity, although the mp3 streaming was making the problem worse.

rajpar3
10-08-2008, 09:15 PM
u can use the below for endless looping-

soundLoop.play(0, int.MAX_VALUE);