Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if html and html:IsValid() then html:Remove() end
- local html = vgui.Create("DHTML") _G.html = html
- html:AddFunction("gmod", "print", print)
- html:AddFunction("gmod", "data", function(data)
- pcall(function()
- local data = CompileString(data, "data")()
- hook.Call("Spectrum", nil, data)
- end)
- end)
- local player = setmetatable(
- {
- },
- {
- __index = function(self, func_name)
- return function(...)
- local tbl = {...}
- for key, val in pairs(tbl) do
- tbl[key] = tostring(val)
- if tbl[key] == "nil" or tbl[key] == "NULL" then
- tbl[key] = "null"
- end
- end
- local str = ("%s(%q)"):format(func_name, table.concat(tbl, ", "))
- html:QueueJavascript(str)
- --print(str)
- end
- end
- }
- )
- html:SetPos(ScrW(), ScrH())
- html:OpenURL("http://dl.dropbox.com/u/244444/gmod_audio.html")
- html:QueueJavascript[[
- var AudioContext = window.AudioContext || window.webkitAudioContext;
- if(!AudioContext) {
- throw "CHROME PLZ";
- }
- var audio = null
- var analyser = null
- function player()
- {
- if (!audio)
- {
- audio = new AudioContext;
- analyser = audio.createAnalyser()
- analyser.connect(audio.destination)
- setInterval(
- function()
- {
- var spectrum = new Uint8Array(analyser.frequencyBinCount);
- analyser.getByteFrequencyData(spectrum);
- var lol = new Array(spectrum.length);
- for(var i = 0; i < spectrum.length; ++i)
- lol[i] = spectrum[i] / 255;
- gmod.data("return {" + lol.join(",") + "}");
- },
- 0
- );
- }
- return audio
- }
- function download(url, callback)
- {
- var request = new XMLHttpRequest
- request.open("GET", url, true)
- request.responseType = "arraybuffer"
- request.send(null)
- request.onload = function()
- {
- gmod.print("loaded \"" + url + "\"")
- callback(request.response)
- }
- request.onprogress = function(event)
- {
- gmod.print(Math.round(event.loaded / event.total * 100) + "%")
- }
- }
- function play(url)
- {
- download(url, function(data)
- {
- gmod.print("decoding " + data.byteLength + " ...")
- player().decodeAudioData(data, function(buffer)
- {
- gmod.print("asdasds")
- var source = audio.createBufferSource()
- source.buffer = buffer
- source.loop = true
- source.connect(analyser)
- source.noteOn(0)
- gmod.print("LOADED AND DECODED")
- })
- })
- }
- window.onerror = function(desc, file, line)
- {
- gmod.print(desc)
- gmod.print(file)
- gmod.print(line)
- }
- ]]
- player.play("http://dl.dropbox.com/u/244444/beetle.mp3")
- print("hi")
Advertisement
Add Comment
Please, Sign In to add comment