Android Audio Streaming

Having spent hours and hours trying to figure out how to get MediaPlayer to work properly on a thread for my last video project and now an audio streaming app, I found there’s an easier way.

The AsyncPlayer class takes care of this for you.

player = new AsyncPlayer(TAG);, Uri.parse(stream), false, AudioManager.STREAM_MUSIC);

For some reason the PocketJourney streaming tutorial for Android 1.0 keeps ranking in all my searches, which is generally too bad because that’s way out of date (incidentally, here is the newer version for 1.5 and later). You don’t need to buffer or double buffer media for the media player anymore. However, the comments on there helped me find AsyncPlayer as well and the 3GP file that Anthony posted to test this.

Now, the next step is to figure out how to get MediaPlayer (which underlays AsyncPlayer) to play an MP3 stream. I don’t know why it won’t, as MP3 is a supported type, but it plays nothing for my test stream.

Update Removed the link to the old streaming article in the hopes that the new one will rank better.

Update Android SDK doesn’t support streaming MP3 (shoutcast) until 2.2 (FroYo). To stream an MP3 stream on earlier OS versions you need to double buffer it either using the PocketJourney code above (which is not very good — it stutters) or using a built-in proxy as the NPR News app does.