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?