aspose file tools*
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


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
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: 119

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: 41574
    
  54
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
 
Don't get me started about those stupid light bulbs.
 
subject: How to play audio in the background