Search code examples
androidandroid-mediaplayer

Android - Playing mp3 directly from the input stream without writing into temp files


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


Solution

  • 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