Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Play mp3 file while downloading?

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.

like image 926
CodeFusionMobile Avatar asked Dec 27 '10 05:12

CodeFusionMobile


2 Answers

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.

like image 55
num1 Avatar answered Nov 20 '22 14:11

num1


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!

like image 42
Rudd-O Avatar answered Nov 20 '22 12:11

Rudd-O