Castillo Posted December 17, 2010 Posted December 17, 2010 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.
Discord Moderators Zango Posted December 17, 2010 Discord Moderators Posted December 17, 2010 Why would you want to add the time played of sound to the total time? Like the song lasts 2 minutes, and when you've heard 1 minute, it says 3 minutes remaining? Or do you want to subtract? https://wiki.multitheftauto.com/wiki/GetSoundPosition returns where in the song you're at, you can calculate remaining with this
Castillo Posted December 17, 2010 Author Posted December 17, 2010 i want time data into a GUI label element.
botanist Posted December 17, 2010 Posted December 17, 2010 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.
Dark Dragon Posted December 17, 2010 Posted December 17, 2010 function msToMinsAndSecs(milliseconds) local minutes = math.floor(milliseconds/60000) local seconds = (milliseconds/1000)%60 return minutes,seconds end
botanist Posted December 18, 2010 Posted December 18, 2010 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now