Could someone please explain this to me line by line?I don't want to just copy paste stuffs without having proper knowledge about what i am actually doing
Uri sArtworkUri = Uri.parse("content://media/external/audio/albumart");
Uri uri = ContentUris.withAppendedId(sArtworkUri, album_id);
ContentResolver res = context.getContentResolver();
InputStream in = res.openInputStream(uri);
Bitmap artwork = BitmapFactory.decodeStream(in);
i am trying to use the code above in the code below to fetch music artists and album etc............................
.................................... ...................... ...........................
public ArrayList<SongDetails> getSongsFromDirectory(File f)
{MediaMetadataRetriever mmr = new MediaMetadataRetriever();
ArrayList<SongDetails> songs = new ArrayList<SongDetails>();
if (!f.exists() || !f.isDirectory())
{
return songs;
}
File[] files = f.listFiles(new Mp3Filter());
for(int i=0; i<files.length; i++)
{
Uri uri = Uri.fromFile(files[i]);
//mmr.setDataSource(null, uri);
if (files[i].isFile()){
SongDetails detail=new SongDetails();
detail.setIcon(R.drawable.ic_launcher);
detail.setSong(files[i].getName());
//detail.setArtist(mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ARTIST));
//detail.setAlbum(mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ALBUM));
songs.add(detail);
}else if (files[i].isDirectory()){
songs.addAll(getSongsFromDirectory(files[i]));
}
}
return songs;
} }
Uri sArtworkUri = Uri.parse("content://media/external/audio/albumart");
This line will, "Creates a Uri which parses the given encoded URI string." (from http://developer.android.com/reference/android/net/Uri.html) A URI is a uniform resource identifier which is unique indentifier for a web resource.
Uri uri = ContentUris.withAppendedId(sArtworkUri, album_id);
ContentUris is a, "Utility methods useful for working with Uri objects that use the "content" (content://) scheme." (http://developer.android.com/reference/android/content/ContentUris.html) with appender ID appends the album_id to the end of the passed in URI. Essentially you're making a new URI to point directly to the album.
ContentResolver res = context.getContentResolver();
Provides access to content model (http://developer.android.com/reference/android/content/ContentResolver.html)
InputStream in = res.openInputStream(uri);
This gives you access to content at URI via an InputStream. InputStreams allow you to read in data. http://developer.android.com/reference/java/io/InputStream.html
Bitmap artwork = BitmapFactory.decodeStream(in);
Lastly this method will load the image at the URI from the input stream. So you now have the image available to you in memory.