Play app in background

Hi mit community I'm having problems with my new music app that I'm making, I want my app to be able to play in background when a listener wants to get out of the app?

How can I make this possible?

To perform operation even after the app-is-closed, you must use Foreground Service. Currently you can use Tasks extension.
Foreground Service help you to run the tasks even the user is not interacting with the app.
This might help you :

4 Likes

Sneha, the resources you have linked to is of the outdated version of the extension...

3 Likes

No it's a radio station app I'm making and I've put a icecast stream into it and when the user presses close button or home button I want the app to be able to play in the background (foreground)

Can you explain to me that how you will be playing the music(radio)?

With my icecast stream in the app plus I'm using centova cast for the radio

1 Like

I just use the audio component for my radio station. Works well, but sometimes it stops. I have implemented an "audio-watcher" which every 3 seconds checks if music is playing & is supposed to be playing and starts the stream again. It works really well. But I have a problem with the back-button. When it is pressed, the music stops. But when the center button (home) is pressed the music doesn't stop. Right now I just disabled backpress. Looking for solution for that (also here)

see @Anke's tip here


Taifun

2 Likes

I have implemented this (ignore battery optimizations) but instead of Foreground Services I use a simple audio-watcher, which works well. Every now and then the music stops but starts again after 2-3 seconds.


The best method I have found for my radio station.

I also tried with a foreground service, but there were problems:

  1. it didn't work. it stopped more frequently and didn't start again either. it performed worse than imagined.
  2. foreground services don't exist for android <8 but my method works on android 6-11 tested. Perhaps older too.
1 Like

In Google play store type In coolvibes-reloaded "NEW" download it play it press home screen you'll see what I'm on about

Try this: AI2 Media Notofication or AI2 Keep Alive or AI2 WakrLock. For Android <8 you only neet to set a wakelock.

2 Likes

i'v tried that i even tested my app in mit and i pressed the
home screen my app was playing in background but im hoping the team
at google can fix this