Android get a built-in album Picture of music files

Source: Internet
Author: User

Code and comments are as follows:

Private Cursor GetCursor (string filePath) {string path = null;    
              Cursor C = getcontentresolver (). query (MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, NULL, NULL, NULL,    
      MediaStore.Audio.Media.DEFAULT_SORT_ORDER);    
      System.out.println (c.getstring) (C.getcolumnindex ("_data")); if (C.movetofirst ()) {do {//Gets the path through cursor, if the path is the same; System.out.printl  
              N ("////////" +filepath);   
             Path = C.getstring (c. Getcolumnindexorthrow (MediaStore.Audio.Media.DATA)); System.out.println ("?????????"  
              +path);    
                  Finding the same path returns, at which point Cursorposition is pointing to the cursor that the path can return to if (Path.equals (FilePath)) {    
                  System.out.println ("audiopath =" + path);    
                 System.out.println ("FilePath =" + FilePath);  
             Cursorposition = C.getposition ();  Break    
      } while (C.movetonext ()); //These two have no effect, when debugging using//String audiopath = c.getstring (c//. Getcolumnindexorthrow (Mediasto Re.    
      Audio.Media.DATA));    
      System.out.println ("audiopath =" + audiopath);    
  return C; private string Getalbumart (int album_id) {string murialbums = ' content://media/external/a    
          Udio/albums ";    
          string[] projection = new string[] {"Album_art"}; Cursor cur = this.getcontentresolver (). Query (Uri.parse (murialbums + "/" + integer.tostring (album_id    
         ), projection, NULL, NULL, NULL);    
          String album_art = null;    
              if (Cur.getcount () > 0 && cur.getcolumncount () > 0) {cur.movetonext ();    
          Album_art = cur.getstring (0);    
          } cur.close ();    
      cur = null;    return album_art;  
   private void GetImage () {Cursor currentcursor = getcursor ("/mnt/sdcard/" +mp3info); int album_id = Currentcursor.getint (currentcursor. Getcolumnindexorthrow (MediaStore.Audio.Media.ALBU   
      m_id));  
      String Albumart = Getalbumart (album_id);  
      Bitmap BM = NULL;    
      if (Albumart = = null) {Mimageview.setbackgroundresource (r.drawable.staring);    
          else {BM = Bitmapfactory.decodefile (Albumart);    
          Bitmapdrawable Bmpdraw = new bitmapdrawable (BM);    
      Mimageview.setimagedrawable (Bmpdraw); }   
     }

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.