You’d think looping audio in Flash would be trivial, right? think again. There’s enough info on the net to tell you what you need, but it’s a bit dispersed, so here it is condensed. Note that this is about looping audio that is on a server, not embedded in your swf. In that case it works out of the box.

The first thing you need is an uncompressed wave file (.wav) that contains a loop. Flash doesn’t support playback of wav files, so you need to convert it to a compressed format. You have two options here: mp3 or aac.

Mp3 has the advantage to be easy to use in Flash but unfortunately contains padding so looping it as is won’t go smoothly.

AAC can be use in Flash 10 and onwards with some trickery described here : http://www.adobe.com/devnet/flashplayer/articles/hd_video_flash_player.html. It has the advantage of not containing padding, so it loops almost perfectly. If that’s enough for you, then good. If not, read on.

If you need perfect, then this post has a pretty good method for it. http://blog.andre-michelle.com/2010/playback-mp3-loop-gapless/ It however does not tell you how to get one necessary information: the number of samples in your loop. If you encode using LAME with the command line (binaries here ), then it will tell you the number of frames. The number of samples per frame is constant with mp3s, it’s 1152. So total number of samples in loop = number of frames * 1152.

Finally, I found this approach to create a loopable mp3 interesting, but I didn’t use it : http://www.compuphase.com/mp3/mp3loops.htm

Pin It