Groups | Blog | Home
all groups > flash actionscript > january 2007 >

flash actionscript : Sound.duration for streaming contents


abeall
1/10/2007 8:41:20 PM
abeall
1/10/2007 10:12:33 PM
To review, I don't have access to the duration via Sound.id3.TLEN, and
converting MP3s to id3 v2 with TLEN is not an option. I am progressively
downloading the file, and Sound.duration gives the milleseconds loaded so far.
There is no way to retrieve the duration without setting it to event
sound(Sound.loadSound('sound.mp3',false)), which is not an option as my MP3s
are large.

Solution? I can roughly calculate the time based on the seconds of audio
downloaded, bytes downloaded and the total amount of bytes in the file:
var percent = _sound.getBytesLoaded()/_sound.getBytesTotal();
var duration = _sound.duration/percent;

It's not perfect, of course, as there are a few hiccups where Flash is
downloading header/footer data, but it works good enough for me!

HTH helps anyone with the same issue.
abeall
1/11/2007 7:28:24 AM
Erm, actually, I'm getting something really strange now. I found that the
results were not quite correct. Long story short, try this:

var s = new Sound();
s.loadSound('sound.mp3',true);
onEnterFrame = function(){
var a = s.duration+"ms : "+s.getBytesLoaded()+" / "+s.getBytesTotal();
}

publish and simulate download, and notice something really weird, here's a
snip:
45166ms : 201558 / 201584
45322ms : 201584 / 201584
45558ms : 201584 / 201584
45793ms : 201584 / 201584

notice how after all the bytes have been loaded(201584 / 201584,
Sound.duration(ms) continues to increase! Why? I tested on a web server and it
did the same. I think I'm stuck at this point.
Actionscripted
1/16/2007 7:07:56 PM
I'm having a very similar problem. I have a streaming player that plays MP3 or
FLV files from a podcast feed.

This play has a playback slider. FLV playback is fine with the player because
who ever wrote that class did a great job. MP3 playback is where things go
nuts. If the MP3 is missing the ID3.TLEN property, playback will resume
normally, but I will be unable to accurately track progress.

There are some rather hack-ish fixes using a timer and checking
downloaded/total bytes, but I have yet to find a reliable and/or accurate
solution.

Sorry to add to the bitch pile instead of clearing it, but I haven't found a
good fix for this. If you find/devise one, please post it here.

NOTE TO ADOBE
````````````````````````````````````````````````````````````````````````````
Please for the love of f*cking christ update the Sound class. It really hasn't
changed over the years, and it's a rotting piece of crap. Half of the methods
don't work the way they're supposed to, and the rest are so poorly implemented
it's disgusting. Take a few notes from the NetStream class, if you must. The
pause() method and the playback tracking are both wonderful examples.
TheDoubleG
4/11/2007 9:32:55 PM
Has anybody found an accurate solution for this? I've tried this to find the
actual duration of a streaming mp3:

totalDuration =
(song_sound.duration/((song_sound.getBytesLoaded()/song_sound.getBytesTotal())*1
00))*100;

However, this still doesn't produce accurate enough results... at least not
for what i'm doing.
AddThis Social Bookmark Button