• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to play audio in the background

 
Daniel Trebbien
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 129
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
use a Service to play audio cause it will call the AUdio Service in Android
 
Daniel Trebbien
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 136
Android Chrome Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Daniel,

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

Thanks & Regards
Pratik Goswami
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic