Hi all, I am a newbie here "> and can you help me how to using Gideros to play a song that locate on internet (mp3 file, for example http://example.com/asong.mp3)? Thanks!
--get your songlocal song ="<a href="http://example.com/asong.mp3"" rel="nofollow">http://example.com/asong.mp3"</a>;
local loader = UrlLoader.new(song)
local function onComplete(event)
--save song in documents folder
local out = io.open("|D|asong.mp3", "wb")
out:write(event.data)
out:close()
--play that song
local sound = Sound.new("|D|asong.mp3")
local channel = sound:play()
end
--print if there is any error
local function onError()
print("error")
end
--you can print a progress
local function onProgress(event)
print("progress: " .. event.bytesLoaded .. " of " .. event.bytesTotal)
end
loader:addEventListener(Event.COMPLETE, onComplete)
loader:addEventListener(Event.ERROR, onError)
loader:addEventListener(Event.PROGRESS, onProgress)
Thanks @ar2rsawseen for support, i will thinking about this way. But i think it is not streaming music way, it downloads and play music on local devices?
yes, downloading is an easy solution. For streaming you will need something more sophisticated and it's hard to tell if thats even possible, because you can play sounds through Sound class only and I don't think it accepts byte streams. Only other option would be a plugin.
Also a problem would be ensuring you maintain a decent internet connection during the streaming process. The fact is that your code would need to be robust enough so that it could handle the loss of connection and potentially data corruption during the streaming process.
WhiteTree Games - Home, home on the web, where the bits and bytes they do play! #MakeABetterGame! "Never give up, Never NEVER give up!" - Winston Churchill
Comments
Likes: sprigame, loves_oi
But i think it is not streaming music way, it downloads and play music on local devices?
Only other option would be a plugin.
#MakeABetterGame! "Never give up, Never NEVER give up!" - Winston Churchill