Reading wav from web for playing audio?


#1

Hi!

The AudioDemo accepts local files to play from the disk. Is there a way to read files from the web given a URL or do I need to download them first and then pass the temporary file to play?

Do we have any sample code to help with this?


#2

I tried using a URL instead of file to read from the web and I got

0x8001010D: An outgoing call cannot be made since the application is dispatching an input-synchronous call.

Anything obvious?


#3

It should be possible to stream from a URL by opening a stream to it instead of a file stream. Of course, seeking in the stream could be a problem, as it’d need to re-open the file and scan from the beginning to get to a new position, so you might need to deal with that.


#4

Would a BufferedInputStream help in that case or should I create a tmp file so that I can read off it in case I want to change positions?


#5

Certainly a bufferedstream would help a lot, but yes, ideally saving it to a temp file would be the best solution if you need to seek. It’s like the way flash video players on the web show you how much they’ve pre-loaded and limit the seeking to that area.


#6

BufferedInputStream then would only help some operations in memory, but the key would be to download the file in the background while enabling access in the main thread so long as the access/seek is within the range of what’s been downloaded.

Are there good controlled examples of multi-threaded stuff like this for the same object?


#7

Don’t think I’ve got any code like it, but it’s kind of similar to what the bufferingaudiosource does, so maybe look in there.