Issue
I'm taking the image from my mp3 files to a Bitmap[] but it causes the application to stop a bit and I'm wanting to use Asynctask to make it smoother.
This is the way I got the bitmap :
Bitmap[] bm = new Bitmap[mySongs.size()];
for (int i = 0; i < mySongs.size(); i++) {
if (mySongs.size() > 0) {
u = Uri.parse(mySongs.get(i).toString());
mediaMetadataRetriever = new MediaMetadataRetriever();
mediaMetadataRetriever.setDataSource(getApplicationContext(), u);
byte[] artBytes = mediaMetadataRetriever.getEmbeddedPicture();
if(artBytes != null) {
InputStream is = new ByteArrayInputStream(mediaMetadataRetriever.getEmbeddedPicture());
bm[i] = BitmapFactory.decodeStream(is);
}
}
How to put it in Asynctask?
Solution
This is what your implementation would look like:
AsyncTask myAsyncTask = new AsyncTask() {
@Override
protected Object doInBackground(Object[] objects) {
//ToDo: Do all the work in here and return result as object
return null;
}
@Override
protected void onPostExecute(Object o) {
super.onPostExecute(o);
//ToDo: Do whatever you want to do with the result in here
}
}
I would suggest creating a static class that extends AsyncTask
or do not pass any context in here or memory leaks might occur
Answered By - Napster
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.