I am developing a module in which I need to show all the video from phone in form of video thumbnails. I have taken BaseAdapter to show all video thumbnails into GridView. The only problem is that I had to write the code extract thumbnail from video file to bitmap in getView() of BaseAdapter.
((Activity) context).runOnUiThread(new Runnable() {
@Override
public void run() {
Bitmap bmThumbnail = ThumbnailUtils.createVideoThumbnail(
videoValues.get(position).getFile()
.getAbsolutePath(), Thumbnails.MINI_KIND);
imageThumbnail.setImageBitmap(bmThumbnail);
bmThumbnail = null;
}
});
I want to load this Asynchronously with some image loader. I have already tried Aquery, Universal Image Loader, Picasso etc but none of them gives asynchronous image loading with memory caching, file caching, failure callback mechanism etc.
Can anyone suggest how can I achieve this efficiently? TIA.
To resolve this issue, I have made a class
VideoThumbLoader
. It asynchronously generated Bitmap and passes it to adapter. So that main benefit is that the whole process is being handled in background thread.The code for class is as below:
And from adapter side, simply call:
P.S: One important thing I had taken a note of was, due to asynchronous downloading of bitmap, there were few cases where thumbnails tend to mix up. So I have tagged the imageview with file path. This way I will have the exact thumbnail for the image.