Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Can we play mp3 file that on internet (streaming music) ? — Gideros Forum

Can we play mp3 file that on internet (streaming music) ?

sprigamesprigame Member
edited September 2012 in General questions
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!

Likes: loves_oi

+1 -1 (+1 / -0 )Share on Facebook

Comments

  • ar2rsawseenar2rsawseen Maintainer
    edited September 2012
    Something like this should work:
    --get your song
    local song = "<a href="http://example.com/asong.mp3&quot" rel="nofollow">http://example.com/asong.mp3&quot</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)

    Likes: sprigame, loves_oi

    +1 -1 (+2 / -0 )Share on Facebook
  • sprigamesprigame Member
    edited September 2012
    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?
  • ar2rsawseenar2rsawseen Maintainer
    Accepted Answer
    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.
  • techdojotechdojo Guru
    Accepted Answer
    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
Sign In or Register to comment.