Android-Get SD card Music media information via system database

Source: Internet
Author: User

When writing something (such as a music player ), you need the MP3 list of SD card ~ START I use the column file again, but get the information of the file (singers, albums, pictures, length, etc.). ) is troublesome, so use this function directly ~

1     Private voidgetmusicpaths () {2         //3         //Get the music list4         //5cursor cursor = getcontentresolver (). Query (MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,NULL,NULL,NULL, MediaStore.Audio.Media.DEFAULT_SORT_ORDER);6         if(Cursor.movetofirst ()) {7              while(!Cursor.isafterlast ()) { 8                 //Song number9                 //int id = cursor.getint (cursor.getcolumnindexorthrow (mediastore.audio.media._id)); Ten                 //Song title OneString Tilte =cursor.getstring (Cursor.getcolumnindexorthrow (MediaStore.Audio.Media.TITLE));  A                 //Song's album Name: MediaStore.Audio.Media.ALBUM -                 //String album = cursor.getstring (Cursor.getcolumnindexorthrow (MediaStore.Audio.Media.ALBUM));  -                 //Song's singer name: MediaStore.Audio.Media.ARTIST theString artist =cursor.getstring (Cursor.getcolumnindexorthrow (MediaStore.Audio.Media.ARTIST));  -                 //path to the song file: MediaStore.Audio.Media.DATA -String URL =cursor.getstring (Cursor.getcolumnindexorthrow (MediaStore.Audio.Media.DATA));  -                 //Total duration of the song: MediaStore.Audio.Media.DURATION +                 //int duration = Cursor.getint (Cursor.getcolumnindexorthrow (MediaStore.Audio.Media.DURATION));  -                 //size of the song file: MediaStore.Audio.Media.SIZE +                 //Long size = Cursor.getlong (Cursor.getcolumnindexorthrow (MediaStore.Audio.Media.SIZE)); A Cursor.movetonext (); at             }  -         } -}

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.