Trying to play an OGG from a remote source

Kaezon
New member
 
Posts: 2
Joined: Tue Oct 18, 2016 02:13
GitHub: kaezon
IRC: kaezon
In-game: kaezon

Trying to play an OGG from a remote source

by Kaezon » Tue Oct 18, 2016 04:22

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
 

User avatar
kaeza
Member
 
Posts: 2141
Joined: Thu Oct 18, 2012 05:00
GitHub: kaeza
IRC: kaeza diemartin blaaaaargh
In-game: kaeza

Re: Trying to play an OGG

by kaeza » Tue Oct 18, 2016 05:05

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.
Your signature is not the place for a blog post. Please keep it as concise as possible. Thank you!

Check out my stuff! | Donations greatly appreciated! PayPal | BTC: 1DFZAa5VtNG7Levux4oP6BuUzr1e83pJK2
 

Kaezon
New member
 
Posts: 2
Joined: Tue Oct 18, 2016 02:13
GitHub: kaezon
IRC: kaezon
In-game: kaezon

Re: Trying to play an OGG

by Kaezon » Tue Oct 18, 2016 05:49

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
 


Return to Modding Discussion

Who is online

Users browsing this forum: No registered users and 5 guests

cron