Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android MediaPlayer - Downloading and Streaming at same time revisited

This question has been asked before, but now with the newer versions of Android (up to Jelly Bean), I was wondering if there's been any progress on downloading AND streaming a file at the same time. From the API, it doesn't look like it's inherently possible, as these are the available setDataSource methods:

void    setDataSource(String path)
Sets the data source (file-path or http/rtsp URL) to use.
void    setDataSource(Context context, Uri uri, Map<String, String> headers)
Sets the data source as a content Uri.
void    setDataSource(Context context, Uri uri)
Sets the data source as a content Uri.
void    setDataSource(FileDescriptor fd, long offset, long length)
Sets the data source (FileDescriptor) to use.
void    setDataSource(FileDescriptor fd)
Sets the data source (FileDescriptor) to use.

Unfortunately it does not accept an InputStream of any kind. There are examples that use the old NPR proxy code that opens a local web server in the Android App, downloads content remotely, and outputs requested data to any listening sockets, however that code is more than 2 years old and it's still used as the standard for accomplishing this task (even though a lot of people report that there are stuttering issues, etc).

I've looked into the MediaPlayer class and wanted to extend it to allow this behaviour however a lot of the implementation is accomplished through native code, and from what I've read, different device manufacturers implement the native audio functionality differently (and if so, I don't want to touch it! :) ).

So, what is the best method to store AND concurrently stream incoming audio data (MP3 or OGG) from a remote server, without discarding the data? Preferably with versions of Android 2.2 and above, but input on any available API would be appreciated.

like image 659
ajacian81 Avatar asked Oct 28 '12 12:10

ajacian81


1 Answers

Building a local proxy is your best bet. I haven't looked at the NPR example, but I've done similar. See my answer here.

like image 66
Dave Avatar answered Nov 15 '22 00:11

Dave