How to design the interaction of activity and service for a simple mp3 player?

I am new to Android and I want to create a simple mp3 player. Now, as I understand it, a good way to do this is to have a service that will be responsible for the MediaPlayer class, and activity, which will be some kind of user interface, as well as send game instructions to the service (play, stop, then, etc.). d.).

My question is, what approach should I use to communicate with the service activity? I tried to figure out these examples , but I don’t see how I can implement the pause, next, previous, etc. functions. Player.

Thus, I am only interested in the concept and, possibly, useful links that will help me a little. Thank!

+3
source share
1 answer

Step # 1: Deploy Service.

Step # 2: Submit the operation command to the service in the form Intentsdelivered via startService()(except for “stop”, which would be a call stopService()).

Step # 3: Ask the service to process these commands in onStartCommand()by making the appropriate calls MediaPlayer(be sure to use prepareAsync()).

Here's a trivial little example of this , for playing and stopping, with exhausted actual use of multimedia. Here is a slightly more complex example of this using Notificationand startForeground()so that the player can continue to play.

+7
source

All Articles