Android scans local music file development case Sharing _android

Source: Internet
Author: User
Tags sqlite database

First, the preface

Originally thought so easy, really did not think, also made a while, make me sweating, want to clap table slam keyboard.
The features you want to implement are:
Through NetEase cloud Music/Baidu Music/qq Music/Cool dog music in an API, through keywords/singers/lyrics to search related songs information, and then play online, download to local, but for now, there is a problem with the API. Access through the browser, the problem is not small, such as the following figure:

But want to access through the mobile phone, the problem appears, the same parameters, the results are very different, and the basic search is not what they want, and then through their own server to visit, or search, and then check the information, temporarily did not solve. So, currently only through the scan QQ music has been downloaded songs, to achieve playback function. In this blog post, I first record the scan music file, as for playback and download, the back if you tidy up, and then posted out.
About NetEase Cloud Music/Baidu Music/qq Music/Cool Dog Music API use, have friends if know suitable for Android, request recommend!

Second, scan local music files

First through the QQ music has been downloading good songs.
Scan implementation:

Scan local Music
if (Environment.getexternalstoragestate (). Equals (environment.media_mounted))
{
  new Thread ()
  {
    @Override public
    Void Run ()
    {
      try
      {
      string[] ext = {". mp3"};
      File File = new file (environment.getexternalstoragedirectory () +/android/data/com.tencent.qqmusic/files/qqmusic/ Song ")//Can be"//////"This string are removed, sweep the range is the entire SD card, I am too slow, and swept out a lot ... Not I want the song, finally or directly written in the download directory of QQ music, in fact, their own app support download, you can download the song designated directory, and then scan this designated directory on the line ~ Global scanning is indeed not appropriate, but not antivirus.
      Localmusiclist = Common.searchmp3infos (file,ext);
      Hander.sendemptymessage (search_music_success);
      } catch (Exception e) {}
      }
    }.start ();
}

The following is the code for Common.searchmp3infos ()

Scan to implement
  static list<string> List = new arraylist<> ();
  public static list<string> Searchmp3infos (file file, string[] ext) {
    if (file!= null) {
      if (file.isdirector Y ()) {
        file[] listfile = File.listfiles ();
        if (listfile!= null) {
          for (int i = 0; i < listfile.length; i++) {
            Searchmp3infos (Listfile[i], ext);
        }
      } else {
        String filename = File.getabsolutepath ();
        for (int i = 0; i < ext.length i++) {
          if (Filename.endswith (ext[i))) {
            list.add (filename);
            Break
    ;
    }}} return list;
  }

Then in the handler through the adapter in the ListView display, the effect is simple like this, or that sentence, do not dislike it ugly:

Well, first sweep it out, show the problem and change it ~ ~ ~

Another method, their own test for a while did not sweep out, that is, from the SQLite database sweeping music files, many friends have mentioned, but do not know where their problems, can only be swept to the recording file ~ I also posted for reference.

public static list 

The above is the entire contents of this article, I hope to learn more about Android software programming help.

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.