I wrote a MusicPlayer in Flash AS3, I must get the length of the music(mp3) first when I create the progress of mp3 loading and playing. But, the Sound.id3 don’t include the [TLEN]Â specification in as3, So I can’t get the length before the sound finished loading. I must find other way.
Below I will list the solution.
When the MusicPlayer load and play the mp3, I can get three value, the sound.bytesTotal, sound.bytesLoaded and sound.length. Divid sound.bytesLoaded by sound.length, get the bytes per milliseconds, divid sound.bytesTotal by that number, get the estimated mp3 length.
var musicLength:Number = sound.bytesTotal / (sound.bytesLoaded/sound.Length)
Just put this script in a Timer, After the Timer start(mp3 playing), you will get the mp3 length.
Of course, the value is an estimated number, If you want to the most accurate length, you should get the length by sound.length after sound finished loading.