PDA

View Full Version : how can i tell what time's left of a sound clip?


zebbah
12-18-2002, 04:22 PM
hello!
i've tried using this code to tell what time is left of a dynamic loaded music clip. mclip = new Sound();
mclip.loadSound("music_clip.mp3", true);
_root.onEnterFrame = function() {
secondsTotal = Math.floor(mclip.duration / 1000);
minutesTotal = Math.floor(secondsTotal / 60);
secondsPlayed = Math.floor(mclip.position / 1000);
minutesPlayed = Math.floor(secondsPlayed / 60);
secondsLeft = (secondsTotal - secondsPlayed) % 60;
minutesLeft = minutesTotal - minutesPlayed;
display = minutesLeft + "." + secondsLeft;
};the problem is that i can't sync the minutes and seconds. this particular clip starts counting down from 4:49 but the minutes don't change when the seconds are 59, but 49. anyone know how i can fix this?

sorry if this is really stupid, but my math sux and so does my as... :P

thanx for any help! :)

jimburton
12-18-2002, 08:40 PM
I think secondsLeft should be:

secondsLeft = secondsTotal - secondsPlayed;

...?

zebbah
12-19-2002, 09:14 AM
thanx, jimburton! :)
but the seconds work fine... the problem's with the minutes not changing accordingly to the seconds. when the seconds reach 0 the minutes don't change until the seconds are 49 since it waits a whole minute before changing...

thnx anyways!