views:

315

answers:

2

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:

  1. call mySound.loadSound(mp3Url, true)
  2. mySound.stop(); // so that the auto-play won't happen
  3. set a timer for the top of the minute (8 seconds from now).
  4. 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.

A: 

I do not believe that this is possible using ActionScript 2. I think you are going to have to either move to AS3 or wrap the MP3 in a SWF.

Even with AS3 you may have to target FP10 in order to use the new sound methods and events that were just added (Sound.extract and Event.SAMPLE_DATA).

In general Sound capabilities in Flash have really lagged until the most recent version of the player.

Branden Hall
A: 

I found your posting (which is a little older now, but... anyway):

there are two options you can use in the Sound-class:

Sound.getBytesTotal

and

Sound.getBytesLoaded

If you compare these two, you can get the amount of bytes loaded at a certain point of time. (See also Sound.onLoad and Sound.onSoundComplete, these two are helpful)

There are also some examples in the Flash help for this.

Greetings,

Draco

Draco