Archive for October, 2007

SHOUTCast, SHOUTCast, Let It All Out

These are the things I could do without.

For the past couple of months, I have been working on a SHOUTCast player app in AIR. When I signed on to do the project, I had absolutely no idea that playing SHOUTCast streams in Flash is a Herculean task. It seems there’s this nagging little memory leak related to Flash loading a never-ending audio stream. Flash doesn’t release the memory for the audio already played, and eventually that audio data just builds and builds and builds until your CPU or memory maxes out. So far, I have found little to nothing in the form of a nice quick solution to this.

That being said, perhaps the most viable current solution was posted at MadArco’s DevBlog . It basically entails streaming the audio for 20-30 minutes, then recreating the audio stream in a new variable, and crossfading the two streams, at which point the original can be released from memory and garbage-collected. It’s a nice idea, but in CS3, after the first couple of swaps, I lost sound altogether, and this problem re-occured no matter which “swapping” method I attempted. MadArco’s solution is in AS2, and perhaps I lost something along the way while attempting to convert it to AS3, or perhaps AS3 isn’t able to handle this particular method.

There’s also a nice explanation of the “swapping” concept here.

So, after even more research (by “research” I mean thinking of new ways to search for a solution in Google) I found a post on FlashBrighton about generating audio and PCM wave data. I also found this on, about using PHP to create a socket connection to read ID3 tags.

See where I’m going with this?

I’m proposing an all-in-one memory-leak-and-ID3-problem fix ShoutCast solution for Flash. Here’s my thoughts on it so far:

1.) Use Socket for getting the ID3 data, and, if possible, getting the stream as well.

2.) Use the FlashBrighton wave-data solution to create the audio from the ByteArray returned by the MP3 stream. This is possible using the URLStream class.

3.) Distribute it as a component or nice reusable class in order to allow beginners to use it easily.

I made some attempts at this yesterday, but the bytecode stuff is way over my head. If anyone has any input, or would like to have a go at this, please leave a comment and let me know what you think!


, , , , ,