Android programming method to get SDcard music files _android

Source: Internet
Author: User
Tags int size

An example of this article describes the way Android programming gets sdcard music files. Share to everyone for your reference, specific as follows:

Copy Code code as follows:
Cursor query (Uri uri, string[] projection, string selection, string[] Selectionargs, string sortOrder);

Uri: Indicates the name of the database to query, plus the name of the table, from Mediastore we can find the parameters of the corresponding information, please refer to the development documentation.

Projection: Specifies which columns in the Query database table, and the corresponding information is included in the returned cursor. NULL returns all the information.

Selection: Specifying query criteria

Selectionargs: Is there a parameter in selection? The symbol here is that the actual value can be substituted for this question mark. What if selection this? , then this string array can be null.

SortOrder: Specify the order in which query results are ordered

The following command returns information about all the music files on the external storage card:

Cursor Cursor = Context.getcontentresolver (). Query ( 
        MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, NULL, NULL, NULL, 
        MediaStore.Audio.Media.DEFAULT_SORT_ORDER); 

Song id:mediastore.audio.media._id

Copy Code code as follows:
Int id = cursor.getint (cursor.getcolumnindexorthrow (mediastore.audio.media._id));

Name of Song: MediaStore.Audio.Media.TITLE

Copy Code code as follows:
String Tilte = cursor.getstring (Cursor.getcolumnindexorthrow (MediaStore.Audio.Media.TITLE));

Album Name of Song: MediaStore.Audio.Media.ALBUM

Copy Code code as follows:
String album = cursor.getstring (Cursor.getcolumnindexorthrow (MediaStore.Audio.Media.ALBUM));

Singer name of the song: MediaStore.Audio.Media.ARTIST

Copy Code code as follows:
String artist = cursor.getstring (Cursor.getcolumnindexorthrow (MediaStore.Audio.Media.ARTIST));

Path to the song file: MediaStore.Audio.Media.DATA

Copy Code code as follows:
String url = cursor.getstring (Cursor.getcolumnindexorthrow (MediaStore.Audio.Media.DATA));

Total playback length of the song: MediaStore.Audio.Media.DURATION
Copy Code code as follows:
Int Duration = Cursor.getint (Cursor.getcolumnindexorthrow (MediaStore.Audio.Media.DURATION));

Size of song file: MediaStore.Audio.Media.SIZE
Copy Code code as follows:
Int size = Cursor.getlong (Cursor.getcolumnindexorthrow (MediaStore.Audio.Media.SIZE));

I hope this article will help you with the Android program.

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.