Search code examples
flashstreammp3detection

Detect if mp3 'file' is a mp3 stream in flash (Action Script 3, AS3)


I have made a player that plays mp3 and does the job very well (not an easy task in flash AS3 to build a secure and stable player). It also can play radio mp3 streams of several radio stations. The 'problem' with mp3 streams is that i do not know how to detect that it is a mp3 stream in flash (no documentation found on the internet and the adobe site). Also I do not know what best way is to buffer these streams.

Anyway, i have made some complicated detection method to decide that it is a stream by checking the getBytesLoaded() and the sound.length changing for a (long) period of time. This is needed to 'tell' the player not to wait while the stream/file is completed or to skip the file when it is corrupt. The problem with this detection method is a slow connection or a fast connection (both has side effects).

For example when it is a slow connection, the detection method fails because it thinks that the file is a stream and when it is a fast connection (or Chrome - that preloads the stream faster than Firefox), it thinks the file is corrupt and skips playing and starts the next file.

This all is not easy to explain but the main question is: Can I see/detect at the beginning of the stream (after opening it) that it is a mp3 stream so that I can skip my silly 'guess-is-it-a-file-or-stream-test'?

Sorry for my bad english today but I have to fix this. Is there anybody that knows a stable solution to this? I have tried a header look-up already but cannot rely on that (too many difference server headers found).


Solution

  • Sorry, there's no way to do that because there is no difference between an MP3 file and MP3 stream - they are exactly the same data. However, if you happened to have a file descriptor, or another program to issue a specific response to your player to acknowledge that the size of the data to be sent is known, then you could treat that response as if it was a file.