views:

112

answers:

3

Hi,

I'm wondering if it is at all possible to get the total duration of an mp3 being streamed in flash?

At the moment I'm using the following code to estimate the lenght but it is always inaccurate

var loadTime:Number=_track.bytesLoaded / _track.bytesTotal;
var loadPercent:uint=Math.round(100 * loadTime);
estimatedLength=Math.ceil(_track.length / (loadTime));
A: 

I don't program in AS3, but can you not read the Length attribtue in the header of the file prior to streaming it?

LnDCobra
I don't think thats available in as3.....?
dubbeat
A: 

Sound class has a length property. This property will be populated once the relevant id3 data for the sound file is loaded. Check out flash.events.Event.ID3 for more info on id3 data.

Amarghosh
Yeah but you only get this once the mp3 has download fully.... or as far as I can see anyway. It constantly changes until the mp3 is fully downloaded
dubbeat
how about listening to `id3` event - did u try that?
Amarghosh
yeah, unfortunately I don't have control over the encoding of the mp3's and often times the lenght property seems to be blank. It was the TLEN attribute of the id3 I've been trying to access anyway
dubbeat
A: 

The long and short of it is if you are playing a streaming mp3 in flash it is impossible to get the exact total playing time until the mp3 is completely downloaded

dubbeat