I'm creating an input stream to buffer and stream a mp3 from cloud .
URL url = new URL("http://xxxx.yyy.com/Demo.mp3");
InputStream inputStream = url.openStream();
Now how do i playback the mp3 from media player without using a temporary file to store it and read back from the same ? I'm developing for Android Lollipop
I'm pretty sure the MediaPlayer can handle remote URLs. Take a look at this example. Check the setDataSource
method from the MediaPlayer
class as well.
EDIT: Since you really really want to use an inputstream, I think you'll need to go low-level. Check the AudioTrack class. This SO answer might help. There are also a couple of issues here and here that might be relevant.
This problem persists even today !!! Check these link out https://code.google.com/p/android/issues/detail?id=29870 and
http://www.piterwilson.com/blog/2014/03/11/android-mediaplayer-not-quite-there-yet/ . There is absolutely no way either to get access and control over the MediaPlayer buffer , neither to feed the buffered mp3 content stored in an byte array into MediaPplayer as an argument to play it . So People either convert the mp3 buffer to PCM and use AudioTrack to play it or write the byte array of the input stream into a local socket and make Mediaplayer read back using the socket file descriptor like mentioned this following link Audio stream buffering
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