Android realizes simple music playback through service
Android music playback effect, simple service on.
Here we will use one of the four components of Android: service
Note: service is one of the main components and needs to be registered.
What is service?
1: "Service" means "service". Like services on windows, services run in the background and undertake quiet and unnoticed work.
2: Service runs in the background. It is an invisible program without interface.
3: Service can be used in many applications. For example, when the user starts other activities when playing multimedia, the program should continue to play in the background; For example, detect the changes of files on SD card; Or record the change of the user's geographic information location in the background; Or start a service to run and listen for certain actions all the time, and so on.
Here is the source code:
MainActivity
Mybroadcastreceiver class (broadcast receiver):
Playingmusicservices class:
Finally, don't forget to register the service in the manifest configuration file:
Create a new raw folder under res and put the downloaded MP3 files into. The songs here are my own, and the songs here are birds.mp3.
Run without error under Android studio.
The above is the whole content of this article. I hope the content of this article has a certain reference value for your study or work. If you have any questions, you can leave a message. Thank you for your support for programming tips.