Android MP3 Player Development Example (1) Music list interface

Source: Internet
Author: User

Learning to develop Android for a year, think about this year's efforts, and indeed harvest a lot. Also found a better job.

Today you are ready to share a project that was previously practiced in the beginner stage. Through this project I really found the development of the feeling of Android software, and gradually entered the formal development of Android. This project was then borrowed from the Mars Teacher's beginner video to do the Anju mobile MP3 player. I have also made improvements, especially in terms of the optimization of lyrics and the addition of progress bars. Because it was done 8 months ago, the level is very 0 basis, the bug should be very much, and now I do not bother to improve again, just hope to provide some help to the novice friends. Or play a starting effect. Then I have a comfortable mind.

The overall introduction of the MP3 player. Very easy, first is the local List page (the interface is very low, we do not laugh):

Watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqv/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/dissolve/70/gravity /center ">

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 adjust accordingly:


First of all, 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);} /** * Each time the local list page is started loading the local MP3 */@Overrideprotected void Onresume () {fileutil fileutil = new Fileutil (); Mp3infos = fileutil.ge TMP3 ("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 Load 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 file with "MP3" suffix under the path folder in the SD card folder of the phone, return the MP3 file collection * Not only obtained the song file name, but also obtained the corresponding lyrics file name * @param path * @return */public list< Mp3info> 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++) {//Gets the name of the file including the mp3 Word if (files[i].getname (). IndexOf ("mp3 >0) {Mp3info mp3info = new Mp3info (); Mp3info.setmp3name (Files[i].getname ()); Mp3info.setmp3size (files[i].length () + "");//To. Separate file names for flags. Deposit the string array string s[] = Mp3info.getmp3name (). split ("\ \"); String lrcname = s[0]+ ". LRC"; Mp3info.setlrcname (Lrcname); Mp3infos.add (Mp3info);}} }return Mp3infos;}}
amongString Sdpath = environment.getexternalstoragedirectory () + "";

each time a local list is entered, the activity's Onresume method is called. The information is then loaded into all local MP3 songs. Then through a simpleadapter, the MP3 information is displayed. Finally, a click event is added to the list. The Click event is an event that clicks on a song to enter the playlist.

All right. The first part is easy, and the second part is about the Music play section.

Android MP3 Player Development Example (1) Music list interface

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.