android - Im trying to display album art within the listview, but having issues -
im able display album art on playing screen, not through listview using same code, difference really, being run through adapter class, artist name , title display each item in list
listview class
public void getsonglist() { //query external audio contentresolver musicresolver = getcontentresolver(); // uri musicuri = android.provider.mediastore.audio.media.external_content_uri; string selection = mediastore.audio.media.is_music + "!=0"; string sortorder = mediastore.audio.media.default_sort_order; cursor musiccursor = musicresolver.query(urimusicshow, null, selection, null, sortorder); //iterate on results if valid if (musiccursor != null && musiccursor.movetofirst()) { //get columns int titlecolumn = musiccursor.getcolumnindex (android.provider.mediastore.audio.media.title); int idcolumn = musiccursor.getcolumnindex (android.provider.mediastore.audio.media._id); int artistcolumn = musiccursor.getcolumnindex (android.provider.mediastore.audio.media.artist); long albumid = musiccursor.getlong(musiccursor.getcolumnindexorthrow(mediastore.audio.media.album_id)); bitmap artwork=null; uri sartworkuri = uri.parse("content://media/external/audio/albumart"); uri uri = contenturis.withappendedid(sartworkuri, albumid); //add songs list { long thisid = musiccursor.getlong(idcolumn); string thistitle = musiccursor.getstring(titlecolumn); string thisartist = musiccursor.getstring(artistcolumn); try { artwork = mediastore.images.media.getbitmap(musicresolver, uri); } catch (ioexception e) { e.printstacktrace(); } songlist.add(new song(thistitle, thisartist, thisid, artwork)); } while (musiccursor.movetonext()); } }
adapter class
public class songadapter extends baseadapter { //song list , layout public arraylist<song> songs; private layoutinflater songinf; //constructor public songadapter(context c, arraylist<song> thesongs){ songs=thesongs; songinf= layoutinflater.from(c); } @override public int getcount() { return songs.size(); } @override public object getitem(int arg0) { return null; } @override public long getitemid(int arg0) { return 0; } @override public view getview(int position, view convertview, viewgroup parent) { //map song layout relativelayout songlay = (relativelayout)songinf.inflate(r.layout.song_item, parent, false); //get title , artist views textview songview = (textview)songlay.findviewbyid(r.id.song_title); textview artistview = (textview)songlay.findviewbyid(r.id.song_artist); // imageview albumview = (imageview)songlay.findviewbyid(r.id.album_cover); //get song using position song currsong = songs.get(position); //get title , artist strings songview.settext(currsong.gettitle()); artistview.settext(currsong.getartist()); // albumview.setimagebitmap(currsong.getart()); //set position tag songlay.settag(position); return songlay; }}
and separate class
public class song { private long id; private string title; private string artist; private bitmap art; public song(string songtitle,string songartist,long songid, bitmap albumart){ id=songid; title=songtitle; artist=songartist; art=albumart; } public long getid(){return id;} public string gettitle(){return title;} public string getartist(){return artist;} public bitmap getart(){return art;}}
im not sure why not displaying needs display, great, thank you
Comments
Post a Comment