1
votes

I am implementing a music player for android and want to implement the search functionality. The search should look for albums, artists and titles and i want them to be displayed differently. Also if i found for example an artist and a title, my app should be able to react properly if the user clicks on one item (artist = show all his songs, title = play the song).

I'm aware that there is a MediaStore provider (http://developer.android.com/reference/android/provider/MediaStore.Audio.Media.html) but it seems like i need more functionality than this. If i do a query like this, i don't now if the artist or the title matched:

String[] projection = {
    BaseColumns._ID,   
    MediaStore.Audio.Media.MIME_TYPE, 
    MediaStore.Audio.Artists.ARTIST,
    MediaStore.Audio.Albums.ALBUM,
    MediaStore.Audio.Media.TITLE,
};

Cursor c = getContentResolver().query(
    MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, 
    projection, MediaStore.Audio.Media.TITLE + " 
    LIKE "+ "'%"+query+"%' OR " + MediaStore.Audio.Media.ARTIST  + " 
    LIKE "+ "'%"+query+"%'", null, MediaStore.Audio.Media.TITLE);

Im right now thinking about creating an index based on the central android music database, but i'm not sure if this is even possible.

Maybe there is a simple solution for this, or there is anybody who already implemented something like this?

1

1 Answers

3
votes

I found a solution myself. There actually is a music search table provided by the android system although it seems like it isn't documented anywhere. Anyway if someone has the same problem try this Uri: content://media/external/audio/search/fancy/

Btw: I found the uri in this sourcecode: http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android-apps/4.2.2_r1/com/android/music/QueryBrowserActivity.java