Android Media Player using the service

I created a MediaPlayer class to play mp3 files. Everything was fine, then my player stopped playing while he was in the background, and I found out that my problem was that I did not create it in the service, so I started reading about the services in order to learn how to create them and use them for my player.

My question is, what is the best way for me to communicate between a service and my application? Should I use the message or send intentions or bind it?

I also need to create a user interface in the notification area, and also show the buffering of progress. Am I creating a listener from the service side for activity, or is there a better way?

I used these examples to find out, but have not yet learned to use the onBind method:

Thanks in advance.

EDIT: I sometimes need to ask the player to send me information about the track that is playing, and the player to tell me buffer updates so that I can update the search bar. Do I keep sending intentions to players or use IBinder?

+4
source share
2 answers

For the connection between service and activity, I prefer the broadcast receiver. Send a broadcast from the Service and receive it in Activity.

+1
source

Link your service to action (tell me your application) when you open it to control MediaPlayer. See a series of training binding services . Use the foreground service so that its priority is always high and it is killed as late as possible in memory. Silentuaton

+3
source

Source: https://habr.com/ru/post/1498715/


All Articles