The solution I'm using to feed binary data directly to MediaPlayer
is to use ParcelFileDescriptor#createPipe() (API level 9) and MediaPlayer#setDataSource(java.io.FileDescriptor).
Here's sample code (untested):
ParcelFileDescriptor[] pipe = ParcelFileDescriptor.createPipe();
FileDescriptor fd = pipe[0].getFileDescriptor();
mediaPlayer.setDataSource(fd);
OutputStream out = new ParcelFileDescriptor.AutoCloseOutputStream(pipe[1]);
From this point on, whatever you write in the output stream will be received by the MediaPlayer
. This is pretty fast since it uses a kernel FIFO to transfer data (no sockets, no TCP) and as far as I understand is fully in RAM (no actual files are used).