This is one of the most frequently asked question in my inbox.
Is it possible to loop MP3 without gaps?
Yes, but to answer the question I like to explain, why gap-less MP3 looping was actually not possible before Flash10 (Except for Flash-IDE encoded MP3 or ugly hacks).
Every audio encoder works by subdivided the audio stream into frames. Each time-frame contains information about the current frequency bands in use. You can easily follow, why an algorithm needs at least a couple of amplitudes (called a window) to analyze the spectrum. A single amplitude does not have any information about frequencies. Imagine a snapshot of a speakers membrane. There is no way to say anything about its velocity, not even its sign.
MP3 also encodes audio with a certain amount of samples each frame. The length of a frame however is not free to choose. That is why encoder add more data (encoder delay) to the audio stream then actually necessary to ensure minimal frame length (depending on algorithm). Unfortunately the engineers of MP3 back then forgot to add the information how much silence they added to the encoded file. To make it absolutely clear: This information is lost for all times. You may write algorithms to estimate the delay, but it is not possible to recover exactly.
Btw: FlashIDE encoded MP3 loop gap-less, cause the SWF contains the original amount.
Does Lame help?
Lame offers embedding this missing information in a hidden MP3 frame. But to get this information you have to load the MP3 as a flash.utils.ByteArray, parse all MP3 frame-headers (no decoding necessary) and do some calculations. But afterward you need to load it again into a flash.media.Sound object to make use of the extract method. So better store this information of each loop in your database or simply somewhere in the Actionscript.
Once you have access to the original amount of samples you can use the Flash10 Playback API to playback your loop and wrap it seamlessly on low-level. You only have to take the encoder delay into account. If you extract from the very beginning you read nothing else than zero amplitudes. Check out the magic-number provided in the source code. This number works perfectly with Lame encoded MP3. This number is not Magic of course. It simply combines the amount of samples LAME added in front of the MP3 – plus – the amount of samples the Flash decoder thinks it were added. You can actually loop waveforms now.
Still to complicated?
Vote for native Vorbis support!