I'm using the MediaStore.Video.Thumbnails.getThumbnail() method to fetch thumbnails for files that I am displaying in a list. This works well to begin with, but after a while the thumbnails that I get back are not the ones that match the file. Once GetThumbnail() starts failing it seems to return only the same Bitmap over and over again, regardless of which file I try. This happens on my HTC Desire, running Android 2.2, and is very hard to reproduce - it will just start happening after some time.
Here is (a cut back version of) my source code:
static public Bitmap GetThumbnailForFile(File p_File, Activity
p_activity)
{
long imageID = GetImageID(p_File, p_activity);
if (imageID < 0)
{
return null;
}
return
MediaStore.Images.Thumbnails.getThumbnail(p_activity.getContentResolver(),
imageID, Thumbnails.MICRO_KIND, null);
}
public static long GetImageID(File p_File, Activity p_activity)
{
long result =-1;
Cursor c =
p_activity.getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
new String[]{MediaStore.Images.Media._ID +""},
MediaStore.Images.Media.DATA +" like '" + p_File.getAbsolutePath(),
null, null);
c.moveToNext();
if (!c.isAfterLast())
{
result = c.getLong(0);
}
c.close();
return result;
}
I'm also doing the same thing to load video thumbnails. I've used some debugging code to inspect the values returned by GetImageID(), and I'm pretty sure that they are correct.
Can anyone see what I might be doing wrong? Or know any reason why the thumbnails stop being properly generated after some time?