4 Replies Latest reply on Feb 25, 2007 11:24 AM by Opera Rat

# converting millisecs to min and sec

I have to turn milliseconds into minutes and seconds for an extra I am using. (Unfortunately the one command that I really need only does TMSF (Track, minutes, seconds, frame). Everything else uses milliseconds. So say I have 164000 milliseconds, that's 2.73 minutes. I need to take the 2 and put it assign it a variable then I need to take the .73 and turn it into seconds, that 43.8 (44) seconds. And I need to assign that a variable. So that I can get my variables into

dmm_CDExtPlayFromTMSF(gTrack, gMin, gSec, 0)

Don't worry about the last number (frame), I don't know what that's all about yet.

--gMark is the milliseconds

gMin = gMark/60000 (and ignore anything after the decimal point WITHOUT ROUNDING UP OR DOWN)
gSec = ??

Basically, I want to parse not round the result of gMark/60000
Can anyone show me the way to do this?
• ###### 1. Re: converting millisecs to min and sec
on MSToHMS(aMilliseconds) ---------------------------------------------
-- INPUT: <aMilliseconds> must be a postive integer
-- ACTION: Converts aMilliseconds to a string with the format
-- "H:MM:SS" or "M:SS", where H is an integer number of hours
-- greater than 0, M is an integer number of minutes and
-- S is an integer number of seconds. Any incomplete
-- seconds (up to 999 milliseconds) are truncated.
-- OUTPUT: Returns a string
---------------------------------------------------------------------

vSeconds = aMilliseconds / 1000
vMinutes = vSeconds / 60
vHours = vMinutes / 60
vMinutes = vMinutes mod 60
vSeconds = vSeconds mod 60

if vHours then
if vMinutes < 10 then
vMinutes = "0"&vMinutes
end if

vString = vHours&":"&vMinutes&":"

else
vString = vMinutes&":"
end if

if vSeconds < 10 then
put "0"&vSeconds after vString

else
put vSeconds after vString
end if

return vString
end MSToHMS
• ###### 2. Re: converting millisecs to min and sec
Thank you. That got me my integers, but now I get an error message:

integer expected
dmm_CDExtPlayFromTMSF(gTrack,gMin,gSec,0)
1

Well last I checked 1 is an integer. It's not "1".

Here is the full script:
global gTrack, gMark, gMin, gSec

on mousewithin

set the moveablesprite of Sprite 9 to true
cursor 293

ConvertFromMillSecs
ScrubMusic

end

on MouseDown
dmm_CDExtPause()
end

on ConvertFromMillSecs

vSeconds = gMark / 1000
vMinutes = vSeconds / 60
vHours = vMinutes / 60
vMinutes = vMinutes mod 60
vSeconds = vSeconds mod 60

if vHours then
if vMinutes < 10 then
vMinutes = "0"&vMinutes
end if

vString = vHours&":"&vMinutes&":"

else
vString = vMinutes&":"
end if

if vSeconds < 10 then
put "0"&vSeconds after vString

else
put vSeconds after vString
end if

the itemDelimiter = ":"
tMin = vString.item[1]
tSec = vString.item[2]
the floatPrecision = 0
gMin = float(tMin)
gSec = float(tSec)

return vString
end

on mouseUp
dmm_CDExtPlayFromTMSF(gTrack,gMin,gSec,0)
end

It doesn't mind the gTrack which is a variable for an integer. So why not gMin, or gSec?
• ###### 3. Re: converting millisecs to min and sec
I don't know why it does that, but I think it is a problem with the way
the xtra is reading in the values. It should work if you explicitly
force the params to be integers:

dmm_CDExtPlayFromTMSF(integer(gTrack),integer(gMin),integer(gSec),0)
• ###### 4. Re: converting millisecs to min and sec
Wouldn't you know? Today, Feb. 25, 2007, a new version of the Xtra came out and it includes dmm_CDExtPlayFromMilliseconds. But your script did work once I changed gMin = integer(tMin) and same for tSec. Thanks for your help