I'd like my Android application to download an mp3 file from the internet and play it like a stream while downloading it. Is this even possible? How would I go about doing it?
Essentially I want the user to be able to listen to the file instantly, but have it keep downloading to the SD Card even if he stops listening, so the whole mp3 file will end up on the SD Card either way.
RTSP or HTTP? If HTTP you can try and remove the Content-Length header which on some mobile devices will allow for immediate invocation of the player. It sounds as though you're pumping the data through a local app. How are you playing the file now?
For Android devices 2.3 and earlier, you need to remove the Content-Disposition response header altogether. This will cause the browser to invoke the audio player of the user's preference.
Try it here: http://declinefm.com/archives select an archive of your choice, and tap the download link.
For modern Android devices, you can dispense with the removal of the CD header.
I have a tutorial here that I wrote inspired on your post:
http://rudd-o.com/linux-and-free-software/how-to-properly-stream-audio-from-your-plone-varnish-site
Enjoy!
I don't believe android provides the functionality you're asking for. But there's one workaround I know of that might work.
http://code.google.com/p/android/issues/detail?id=739 is an open ticket with a lot of discussion that relates to what you're describing. In the 5th comment seeingwithsound says
To be honest I haven't played with MediaPlayer too much, so I can't give you too many details on how to "control MediaPlayer's buffering". But assuming you can get that to work, I suggest that you download your .mp3 file to (a) temporary file(s) which you can then point MediaPlayer to.
Sorry this answer is so vague, but you're entering territory that few others have before attempted. Good luck.