Teach you to easily make Android music player

Enjoy our refreshing interface~

If we only use activity to make such things, it's childish. Of course, we use service here. First, we start with the code of service: 1. If we want to access the properties and methods of service, the activity must be implemented by bindservice, and the onbind method in service must also be implemented, The ibinder object returned by onbind is used in the serviceconnection of the activity. 2. The activity obtains the ibinder object, and can further obtain the service object and player object for access. 3. Environment. Getexternalstoragedirectory() is used to obtain the contents in SD, whether it is the SD card built in the mobile phone or the SD card added by the user later; What getexternalfilesdir() gets is the internal storage space of the phone, / data / data / your_ Package /, the stored files will be deleted with the uninstallation of the application. 4. The service interacts with the activity by sending a broadcast

Next, add the activity Code: 1. Obtain the service object through the ibinder object. 2. The method of accessing the service after obtaining the service object. 3. Refresh the page through the receiver

4. Finally, the XML layout file is attached, which can be regarded as complete code upload:

For more information about the player, please click "Java player functions" to learn.

The above is all the code for making Android music player. I hope it will help you learn.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>