Page 1 of 1

Trying to play an OGG from a remote source

PostPosted: Tue Oct 18, 2016 04:22
by Kaezon
I'm trying to see if I can get an OGG to play from the web using the Minetest http api.
I've gotten all the way to getting the callback to execute, but it seems that minetest.sound_play() isn't actually playing the data from response.data
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
if http then
  http.fetch({url = "hpr.dogphilosophy.net/test/ogg.ogg", timeout = 30},
    function(res)
      minetest.log("error", "JUKEBOX: HTTPRequest called back!")
      local meta = minetest.env:get_meta(pos)
      for k, v in pairs(res) do
      minetest.log("error", k .. " = " .. tostring(v))
    end
    meta:set_string("hwnd", minetest.sound_play(res.data, {gain = 0.5, max_hear_distance = 25}))
    minetest.log("error", "JUKEBOX: Sound played?")
  end)
end

And this is the output I get from that at runtime:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
2016-10-18 00:04:52: ACTION[Server]: Mod performs HTTP request with URL hpr.dogphilosophy.net/test/ogg.ogg
2016-10-18 00:04:57: ERROR[Server]: JUKEBOX: HTTPRequest called back!
2016-10-18 00:04:57: ERROR[Server]: succeeded = true
2016-10-18 00:04:57: ERROR[Server]: code = 200
2016-10-18 00:04:57: ERROR[Server]: completed = true
2016-10-18 00:04:57: ERROR[Server]: timeout = false
2016-10-18 00:04:57: ERROR[Server]: data = OggS
2016-10-18 00:04:57: ERROR[Server]: JUKEBOX: Sound played?

I've confirmed that using a local file instead of res.data works fine.
Am I missing something?

Edit: I tired writing res.data to a file and ended up with a file containing "OggS." I guess the API doesn't let me work with binary data.
Edit 2: Yeah, looks like the engine just pushes a string over to the API. https://github.com/minetest/minetest/bl ... tp.cpp#L86

Re: Trying to play an OGG

PostPosted: Tue Oct 18, 2016 05:05
by kaeza
That's because sounds are sent to client during load time. You cannot add sounds at runtime, sadly.

Single player also uses client-server architecture, so you cannot hack around it.

BTW, nice name.

Re: Trying to play an OGG

PostPosted: Tue Oct 18, 2016 05:49
by Kaezon
kaeza wrote:That's because sounds are sent to client during load time. You cannot add sounds at runtime, sadly.

Single player also uses client-server architecture, so you cannot hack around it.

Darn, I was halfway done implementing a base64 decoder to write encoded OGGs down from my AWS S3.

kaeza wrote:BTW, nice name.

Back at ya :P