android - How to actually search for a song in a mediastore cursor using a string -


i have set cursor still struggling searching it. how search track name? how id can pass mediaplayer? have tried different things didn't succeed.

basically, want know how search mediastore string (string songtoplay in case), results, id of best match , pass mediaplayer service play in background. thing asking how id though.

this code using:

uri uri = mediastore.audio.media.external_content_uri; string[] songtoplay = value.split("play song");     string[] searchwords = songtoplay[1].split(" ");                 string [] keywords = null;                 stringbuilder = new stringbuilder();                 where.append(mediastore.audio.media.title + " != ''");     string selection = where.tostring();                     string[] projection = {                             basecolumns._id,                                mediastore.audio.media.mime_type,                              mediastore.audio.artists.artist,                             mediastore.audio.albums.album,                             mediastore.audio.media.title                     }; (int = 0; < searchwords.length; i++) {                         keywords[i] = '%' + mediastore.audio.keyfor(searchwords[i]) + '%';                     }                  cursor cursor = this.managedquery(uri, projection, selection, keywords, mediastore.audio.media.title);                               if (cursor.movetofirst()) {                     do{                         test.settext(cursor.getstring(cursor                                 .getcolumnindex(mediastore.audio.media.display_name)));                     }while(cursor.movetonext());                 } 

i'm confused , of code internet. have been trying 2 days now, that's why i'm asking here. i've done hours of trying myself.

edit: current code. how supposed find location - music id or whatever need play song cursor?

uri uri = mediastore.audio.media.external_content_uri;             string songtoplay = value.replaceall("play song", "").trim();             int music_column_index;             string[] projection = {                     mediastore.audio.media._id,                        mediastore.audio.artists.artist,                     mediastore.audio.albums.album,                     mediastore.audio.media.title             };               @suppresswarnings("deprecation")             cursor cursor = this.managedquery(uri,                      null,                      mediastore.audio.media.title + "=?",                      new string[]{songtoplay},                      mediastore.audio.media.title + " asc");  

this search mediastore songs title equal value of songtoplay string.

cursor cursor = getcontentresolver().query(     mediastore.audio.media.external_content_uri,      null,      mediastore.audio.media.title + "=?",      new string[]{songtoplay},      mediastore.audio.media.title + " asc"); 

you can of course query cursor id (and other column) of results.

while (cursor.movetonext()) {     string path = cursor.getstring(cursor.getcolumnindex(mediastore.audio.media.data));     long id = cursor.getlong(cursor.getcolumnindex(mediastore.audio.media._id));     // whatever else need } 

however require exact match, may use like operator more fuzzy match.


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -