GeeCON Prague 2014*
The moose likes Android and the fly likes How to play audio in the background Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Mobile » Android
Bookmark "How to play audio in the background" Watch "How to play audio in the background" New topic
Author

How to play audio in the background

Daniel Trebbien
Ranch Hand

Joined: Jul 10, 2007
Posts: 44
What is a good way to play streaming audio in the background so that audio continues to play while the user switches between activities of the app, but stops whenever, for example, the user has an incoming phone call?
Michael Rivera
Ranch Hand

Joined: Dec 31, 2007
Posts: 121

use a Service to play audio cause it will call the AUdio Service in Android


So many things to do so little time !!!
@mikedroid myLinkedIn
Daniel Trebbien
Ranch Hand

Joined: Jul 10, 2007
Posts: 44
Michael Rivera wrote:use a Service to play audio cause it will call the AUdio Service in Android


Do you know of a good tutorial for this?
Pratik Goswami
Ranch Hand

Joined: Mar 02, 2009
Posts: 136

Hi Daniel,

You can use AsyncTask to continue playing audio even if user switches or move to another screen.

Thanks & Regards
Pratik Goswami


iOS * Android Developer
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42033
    
  64
You can use AsyncTask to continue playing audio even if user switches or move to another screen.

That's not a good idea, as AsyncTask's are part of the Activity, and thus eligible for termination whenever Android feels like it. Services are better suited for longer-running tasks.


Ping & DNS - my free Android networking tools app
 
GeeCON Prague 2014
 
subject: How to play audio in the background