androidandroid-mediaplayeraudio-streamingaudiobuffer

How to play audio from buffer in Android


I am trying to play audio from buffer which is streamed from android to android. Tried using AudioTrack which works for PCM format only.To play MP3, I am looking to use MediaPlayer but it doesn't support playing from buffer.How can I make it work?


Solution

  • Well, you have a few options... 1) (Probably bad option) You can actually make what you ask work by using a local proxy to feed MediaPlayer the MP3 data. This is not very straightforward, but I am sure it can work. 2) Decode the MP3 data and use AudioTrack. This is the more lightweight option if you are willing to use a 3rd party library for decoding. See this link. There are probably other libraries that can be used for decoding.

    UPDATE: Unfortunately, the link I provided is now broken. My apologies for not capturing more information in the answer. As the OP says in the comment, decode using MediaCodec and play back using AudioTrack.