It only needs a FILE if you call SDL_RWFromFP.? But if you call SDL_AllocRW instead, and then set the members manually, you can wrap it around a stream easily enough.________________________________
From: hmartinez <hector.martinez at sensetrix.com>
To: sdl at lists.libsdl.org
Sent: Tuesday, May 29, 2012 11:07 PM
Subject: Re: [SDL] Streaming audio
Mason Wheeler wrote:
Looks like you’re trying to treat this as one problem, when it’s actually two. You need to be able to do two separate things, download a file and play a song from a stream, and then combine them.
The various SDL music-playing functions only know how to play files from streams. (And a few helper functions to load a local file from disc into a stream, so they can play from the stream.) But when it comes down to it, a SDL_RWops is a stream interface, and you can wrap one around any object from any language that implements the basic stream operations.
So what you need now is to figure out how to open an HTTP connection to your music location and get back a download stream. Exactly how that’s done depends on what language and what Internet framework you’re using, but you should be able to figure it out with a bit of research. Once you’ve got that, just wrap your stream in an SDL_RWops and feed it to SDL.
…except that under some circumstances (I forget exactly which) the SDL code will want to read the entire song into memory all at once instead of playing it continually from the stream. This is obviously designed for local files and won’t work for streaming audio from the Internet. So keep that in mind and if it becomes a problem, you’ll have to look into it and maybe ask some questions here. But first things first, figure out how to get an HTTP stream.
Mason
Hi Mason, thank you for your answer.
In fact, when I was trying to use SDL_RWops, I was trying to do as you say in your message. As it needs a FILE object as first argument, I was trying to feed it with a FILE that was being updated with ‘fread’ function, but with no luck (I mean, I wasn’t able to get the stream). That’s why I was wondering that maybe somebody could help me in getting the stream, because I thought it should be easy to do.
I am using c++ and the internet file I want to stream is just a normal one that you can find in any webpage (I mean http://…/audio.wav).
SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org