I am trying to play an MP3 using Actionscript 2. I have the following requirements:
- I don't want to wait for the MP3 to load before playing it.
- I want to know when enough of the MP3 has downloaded that I can start playing it.
- I don't want the MP3 to start playing immediately: I need to control when the play starts.
An example scenario is that I need to start playing a 30-second MP3 exactly 8 seconds from now (at the top of the minute, let's say). Depending on the connection, I may or may not be able to download the entire MP3 by then, but I can almost certainly download enough to start playing without interruption.
The closest way I can see to do this is Sound.loadSound(url, isStreamable)
. If I pass true for the isStreamable
parameter, though, the sound will start playing immediately (docs say: Playback begins when sufficient data has been received to start the decompressor).
I've tried the following:
- call
mySound.loadSound(mp3Url, true)
mySound.stop();
// so that the auto-play won't happen- set a timer for the top of the minute (8 seconds from now).
- In the timer, check the duration of the sound (which continues to get bigger as the file gets loaded). If the duration is < 5 seconds, we don't have enough buffered sound, so generate an error. Otherwise, start playing the sound with
s.start(0)
.
The behavior I see is that the sound doesn't start playing until it's entirely downloaded.