Is it possible to:
- use http request to get the html for a website with a sound embedded in it (tick)
- download this sound
- save and play this sound
Is it possible to:
Edit: i now know the url of the sound ( it is stored on google drive, which also hosts the test site)
I am using this code so far.
function setup()
http.request("https://googledrive.com/host/0B0HeB0Wj_VwNZkpNbkM5dVowRWc/music.mp3",
didGetdata,Error)
end
function didGetdata(data,status,headers)
print(data)
for k,v in pairs(headers) do
print(k..v)
end
end
function Error(e)
print(e)
end
Could someone please point me in the right direction.
I experimented with sound & music downloading/playing when Codea 2.0 came out. I found you could http.request a sound file, take the data it returned (first parameter in success function) and write it to a .wav or .mp3 file in your assetpacks. I also made an easy writeFile function to make the sound/music file. (First parameter is the name of the asset [end it with .mp3 or .wav, whatever the filetype is], second is what to write [the data returned by the web page])
Install
= {
--[[
--------
writeFile
Easy function for writing data into a file
fileName: Name of the target file in Dropbox.assetpack, including extension
data: Data to write into target file
--------
--]]
writeFile = function(fileName, data)
local file = os.getenv("HOME") .. "/Documents/Dropbox.assetpack/" .. fileName
wFd, err = io.open(file, "w")
if wFd == nil then
error("\
\
Error creating/editing file " .. fileName .. "\
\
Error: " .. err)
--assert(wFd ~= nil, "Error creating/editing file " .. fileName)
end
wFd:write(data)
wFd:close()
print("File " .. fileName .. " installed!")
end,
}
Wow thanks, will try it when I can. Thanks again
@skythecoder could you explain this strange syntax: install = { func=function() end,}
?
i’d like to know!
thanks
I think it’s beacuse the function is defined within a table.
@Jmv38 Install is a table, and “writeFile” is a function within the table. It’s like classes, but without metatables. I made an Install table originally because I planned to add in more functions, but writeFile was all I needed. I might make more, later.