Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -----------------------------------------------------------------------------------------------------------------------------------------
- -- @CloneTrooper1019, 2014
- -- This function allows you to get the length of a sound using its asset hash.
- -- Please note that this function only gives you a rough estimate of the sound's length
- -- It could be around +/- 2 seconds off, but its certainly closer than nothing.
- -- It requires the HttpService to be enabled in order to use as it requests the
- -- sound informatioh from the website.
- -- To get the asset hash of a sound, you must go to an audio page.
- -- For example: If we wanted to get the hash for this sound
- -- http://www.roblox.com/Leeeeeeroy-Jenkins-item?id=130758889
- -- We have to replace it with this in the url:
- -- http://www.roblox.com/asset/?id=130758889
- -- If the audio is supported, you should be redirected to a rbxcdn link like this:
- -- http://c2.rbxcdn.com/7f3aa807276de0440acc4f167cdc9ea8
- -- Those random keys next next to the / in the url are actually the hash of the sound.
- -- From there, we set the SoundId of the audio you want to get the length of to this:
- -- http://www.roblox.com/asset/?hash=7f3aa807276de0440acc4f167cdc9ea8
- -- Now you can call getSoundLength on the sound.
- -- Be aware that this function may flood the output with warnings, just try to ignore it :P
- -----------------------------------------------------------------------------------------------------------------------------------------
- function estLength(sound)
- local http = game:GetService("HttpService")
- local network = game:GetService("NetworkServer")
- if http then
- local soundId = sound.SoundId
- local first,last = string.find(soundId,"?hash=")
- if not first or not last then
- error("The SoundId of "..sound:GetFullName().." must have a hashed version of the asset url. Read the script for more information.")
- else
- local hash = string.sub(soundId,last+1)
- if #hash == 0 then
- error("Invalid Hash")
- end
- local str
- for i = 0,9 do
- if str then break end
- pcall(function ()
- str = http:GetAsync("http://c"..i..".rbxcdn.com/"..hash,false)
- end)
- end
- if not str then
- error("Unable to find sound info for hash: "..hash)
- end
- print("Estimated Audio Length: "..#str/20000)
- return #str/20000
- end
- else
- error("The HttpService must be enabled in order to use this function")
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement