Hi everyone, I’m having problems creating an mp3 player, it’s actually a plug-in component for our content management system so unfortunately I can’t use the default component that flash provides.
I can load the mp3 fine by using loadSound(). And of course have the preloading option set to true.
So then I have an interval that updates every 100 miliseconds that tracks the position of the playhead.
If the user plays the file when it is still preloading the playhead goes all over the place. Look at the code I have below:
//---show the amount loaded
amountLoaded = (s.getBytesLoaded() / s.getBytesTotal() )
loader.loadBar._width = amountLoaded * 202.1
loader.scrub._x = s.position / s.duration * 202.1
So loader is the full bar which by default is empty.
loader.loadBar is the coloured bar inside which will show how much of the track has been loaded
loader.scrub is a little triangle pointing to your current place within the track.
202.1 is the width of the bar
The problem I have is that s.duration seems to take the duration of what’s been downloaded, not the duration of the entire track. So if it has loaded 20 seconds of a 1 minute track, the pointer will show your position assuming you only have a 20 second track, so it will look like it is halfway through after just 10 seconds!
I have almost identical code for a video scrub bar and it works perfectly. So I have no idea what is wrong with this. Surely someone else must have had this problem!