Search for music files with the environment

I have been studying this for hours. I looked at android javadoc - MediaStore and I just don't get it. I was looking for examples. Nothing.

I want to search a string in the music library. I have a basic idea in my head (to get a music library database, look for it as if you were using sqlite DB), but I literally have no idea how to do this.

I also found a URI for external SD media files - MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,

but I don’t know what to do with it.

Some starting points will be enjoyable.

Thanks.

+4
source share
1 answer

MediaStore more or less an SQL database. There are many ways to request it. By album, by artist, by playlist, by song, etc. This will return the Cursor all songs, for example.

 Cursor cursor = getContentResolver().query( MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, null, null, null, MediaStore.Audio.Media.TITLE + " ASC"); 

After that, you can get specific columns:

 while (cursor.moveToNext()) { String title = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.TITLE)); // Whatever else you need } 
+5
source

Source: https://habr.com/ru/post/1494340/


All Articles