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.
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
However, as a workaround I next stream my synthesized data to temporary files much like you consider streaming your HTTP streams to files, for subsequent playback of these files via MediaPlayer. [...] It looks though like your problem might be served by more control over MediaPlayer's buffering, because you are essentially concatenating streams through some cache mechanism (buffer) ...
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.
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With