Jump to content

question about (getSoundLength)


Castillo

Recommended Posts

hey, i'm creating a sound player with the new 1.1 functions (so this way when its released i can use it :)) and i would like to add the time played of sound and total time like: 1:45 but my problem is, how i can make this function (getSoundLength) return like this? is even possible?

Thanks in advance.

Link to comment

You basically want to convert milliseconds to minutes, isn't it?

Try diz:

  
function msToMinutes ( ms ) -- Returns ( minutes, seconds ) 
    local sec = ms/1000 -- Converts all MS to seconds 
    local min = 0 -- We have no minutes counted yet 
    if sec < 60 then -- if we have at least one minute 
        repeat sec = sec-60 -- Start counting minutes 
            min = min + 1 -- So add a minute 
        until sec < 60 -- If there are no minutes left 
    end 
    return min, sec -- We are done, and return the minutes and seconds 
end 
  

I haven't tested it, but this should work.

Link to comment
function msToMinutes ( ms ) 
    local m = math.floor ( ms/60000 ) 
    local s = math.floor( (ms/1000)%60 ) -- Will return round integers, instead of big long floats. 
    return m, s 
end 

Edit of Dragons version. Tested & Working. My other function doesn't work. Use this one :)

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...