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.