Wednesday, October 1, 2008

Sound complete event problem in AS3 (with some mp3 files)

Ok, another frustrating one. It appears that the Sound.complete event in AS3 does not work properly. Here is what is happening:

I'm building an MP3 player and want to include a progress bar that allows a user to scrub the track. Since the Sound object can't tell at the beginning how long the track is until its fully loaded, I'm using the rss feed tag to initially set the duration. Once the sound has fully loaded I have an event handler that gets called by the Complete event. This usually works -- but I have found that for SOME mp3 files (not sure why its only some of them) when the event.COMPLETE fires the Sound.length shows that the sound is TWICE as long as it really is. A second later it return sthe proper value but that means I can't rely on the event to determine what the true length of the file is.

At least I know where to put the hack in (I'll probably wait a second or two and THEN sent the final duration)

Since I didn't get any other Google hits for this exact error (although others have reported errors with the Sound object--including the COMPLETE event), I thought I'd blog it.

Hope it helps somebody else...

No comments: