c# - Get Music files details only -
basically trying details of music file inside android device (ex. music's title, artist, etc) , store them list<>
.
(songdata
contains list, , contains list of song
object.)
public void populatesonglist(context context) { songdata songdata = new songdata(); android.net.uri musicuri = android.provider.mediastore.audio.media.externalcontenturi; //used query media files. icursor musiccursor = context.contentresolver.query(musicuri, null, null, null, null); if (musiccursor != null && musiccursor.movetofirst()) { int songid = 0; //get columns. int songtitlecolumn = musiccursor.getcolumnindex("title"); int songartistcolumn = musiccursor.getcolumnindex("artist"); //add songs list { string songtitle = musiccursor.getstring(songtitlecolumn); //tried, file name not contain file extension. if (songtitle.tolower().contains(".mp4") || songtitle.tolower().contains(".m4a")) { string songartist = musiccursor.getstring(songartistcolumn); songdata.addnewsong(new song(++songid, songtitle, songartist, null)); } } while (musiccursor.movetonext()); } }
the code works in do..while
loop, songtitle
contains other files not music files well.
tried checking file extensions not work, , after using debugger again, file name given not contain file extension.
so how make sure grabs details music file, , not other kind of files?
(also, want grab name of artist of music file, apparently int songartistcolumn = musiccursor.getcolumnindex("artist");
not seem work.)
finally, how image of music file? (the song image).
you can try use musiccursor.getcolumnnames()
see file allowing work with.
here's image of possible results can if execute it. musiccursor.getcolumnnames()
return results in string[]
can use list<string> songinfo = new list<string>(string[]);
a problem might nullexception
, happens when data you're trying work have value of null. you'll value directly file if artist or other values unknown.
i don't know image file stored, if it's stored music file stored in byte[]
. you'll need convert byte[]
image.
Comments
Post a Comment