Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Searching for music files with mediastore

Tags:

android

I have been researching this for hours now. I've looked at android javadoc - MediaStore and I just don't get it. I've looked for examples. Nothing.

I want to search the music library for a string. I have the main idea in my mind (get music library DB, search it like you would a sqlite DB) but I literally have no idea how to do it.

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

but I don't really know what to do with this.

Some starting points would be nice..

Thank you.

like image 544
Matt Smith Avatar asked Jul 30 '13 16:07

Matt Smith


People also ask

How do I find my music files?

From the Home screen, tap Apps > Music Player . The Music Player application searches your phone for music files you copied into it, then builds a catalog of your music based on the information contained in each music file.


1 Answers

The MediaStore more or less is an sqlite DB. There are many ways to query it. By album, by artist, by playlist, by song, and so on. This will return a Cursor of all songs, for example.

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

You can then get specific columns from it like so:

while (cursor.moveToNext()) {
    String title = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.TITLE));
    // Whatever else you need
}
like image 75
Ken Wolf Avatar answered Sep 22 '22 21:09

Ken Wolf