Learn Android Development has a year, think of this year's efforts, indeed also harvested a lot, also found a relatively good job. Today, I'm going to share a project that I've been practicing at the beginner stage, and through this project I've really found the feeling of developing Android software, and I've gradually become a regular developer of Android. This project was then borrowed from the Mars Teacher's beginner video to do the Anju mobile phone MP3 player, and has made improvements, especially in the lyrics of the optimization and add progress bar. Because it was done 8 months ago, the level is very elementary, the bug should be a lot, and now I do not bother to improve again, only hope to provide some help to the beginner's friends, or play a good effect, then I am satisfied.
First, the overall introduction of the MP3 player. Very simple, the first is the Local List page (the interface is very low, we do not laugh):
The left side of the list is the song name, and the right is the corresponding song size (bytes).
Tap a song and go to the play page to play, pause, and stop the music. Adjust the progress bar to adjust the progress of the song playback, the lyrics also correspond to adjust:
First from the local music list to talk about, relatively simple first look at the code:
Import Java.util.arraylist;import java.util.hashmap;import Java.util.iterator;import Java.util.List;import Android.app.listactivity;import Android.content.intent;import Android.os.bundle;import Android.util.Log;import Android.view.view;import Android.widget.listview;import Android.widget.simpleadapter;import android.widget.Toast; public class Localmp3activity extends listactivity{list<mp3info> Mp3infos = null; Simpleadapter simpleadapter = null, @Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate ( Savedinstancestate); Setcontentview (R.layout.localmp3);} /** * Reload local MP3/@Overrideprotected void Onresume () {fileutil fileutil = new Fileutil () each time the local list page is started; Mp3infos = Fileutil.get MP3 ("mp3/");//for (Iterator Iterator = Mp3infos.iterator (); Iterator.hasnext ();) {///////////////////mp3info Mp3info = (mp3info) iterator.next ();//LOG.D ("Yinan", "localmp3activity--------" + Mp3info.tostring ());//}if (mp3infos.size () = = 0) {Toast.maketext (this, "No local Music", 0). Show (); simpleadapter = Buildadapter (Mp3infos); Setlistadapter (Simpleadapter);} Else{simpleadapter = Buildadapter (Mp3infos); Setlistadapter (Simpleadapter);} Super.onresume ();} /** * Encapsulates the adapter for the listview * @param mp3infos * @return */private simpleadapter buildadapter (list<mp3info> mp3infos) {List <HashMap<String,String>> list = new arraylist
See loading local MP3 Here is a Fileutil class, which is the class for this program to handle files and see how the GetMp3 method is implemented:
/** get the phone SD card directory under the path directory under the "MP3" as the suffix of the file, return MP3 file collection * Not only obtained the song filename, also obtained the corresponding lyrics file name * @param path * @return */public list<mp3info& Gt GETMP3 (String path) {list<mp3info> Mp3infos = new arraylist<mp3info> (),//file f = new File (sdpath+ "/" +path); file[] files = f.listfiles (); for (int i = 0; i < files.length; i++) {//Get the file name containing the MP3 word if (files[i].getname (). IndexOf ("mp3 >0) {Mp3info mp3info = new Mp3info (); Mp3info.setmp3name (Files[i].getname ()); Mp3info.setmp3size (files[i].length () + "");//With. Separate file names for flags, and string arrays into strings s[] = Mp3info.getmp3name (). split ("\ \"); String lrcname = s[0]+ ". LRC"; Mp3info.setlrcname (Lrcname); Mp3infos.add (Mp3info);}} }return Mp3infos;}}
whichString Sdpath = environment.getexternalstoragedirectory () + "";each time the local list is entered, the activity's Onresume method is called and the information for all local MP3 songs is then loaded. Then through a simpleadapter, the MP3 information is displayed. Finally, a click event is added to the list, which is the event that clicks on a song to enter the playlist.
Well, the first part is very simple, and the second part is about the Music play section.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Android MP3 Small Project Development Example (1)