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

flash actionscript : Timer Counter for video duration


Flashm NO[at]SPAM n
1/18/2007 8:34:15 PM
Hi,

I'm in the process of creating a video control for a swf video. I'm trying to
work out a way to display the total duration of the video and the current play
time. So far I have worked out the total time by using _root._totalframes /
framerate (12fps) /60 to give me the duration in minutes. What I'm having
problems with is using the same method but with the _currentframe to work out
the current playtime of the video. I can get the minutes to display properly
using the Math.floor function but I have been unable to get the correct display
of the seconds. Clear as mud??!

For example say my video has a total duration of 2 mins and 36 seconds. I
want the playtime to update whilst the movie is playing until it reached the
total durations.....1:46 of 2:36 etc.

Any ideas?

Thanks
kglad
1/18/2007 8:57:31 PM
instead of dividing by 60 to change your total time from seconds to fractional
minutes (and then rounding), just pass your total seconds to the function
below. it will return the time in the format you want:



function timeConvertF(s) {
var s = Math.round(s);
var m = (Math.floor(s/60)).toString();
s = (s%60).toString();
if (s.length<2) {
s = "0"+s;
}
return m+":"+s;
}
Flashm NO[at]SPAM n
1/19/2007 10:47:55 AM
kglad,

Great your a star. Works perfectly!

kglad
1/20/2007 7:04:02 AM
AddThis Social Bookmark Button