How to play streamed audio in background on Android?

neowinston picture neowinston · Oct 10, 2012 · Viewed 22.9k times · Source

I have an Android application that plays streamed audio from the Internet using the MediaPlayer class.

How do I let it continue to play the audio on the background when the user hits the home button to run other applications?

While running other apps, I'd like it to continue to play the audio.

Answer

Anup Cowkur picture Anup Cowkur · Oct 10, 2012

You have to use something called Android Services.

From the docs:

"A Service is an application component representing either an application's desire to perform a longer-running operation while not interacting with the user or to supply functionality for other applications to use."

Here's the excellent official guide to using services to get you started: http://developer.android.com/guide/components/services.html

Here's a good tutorial on building an audio player: http://www.androidhive.info/2012/03/android-building-audio-player-tutorial/

Here's a video tutorial for building a streaming music player: http://www.youtube.com/watch?v=LKL-efbiIAM