我正在尝试创建一个包含视频详细信息的 ListView,包括视频缩略图。
在适配器的 getView 方法中我调用
new ThumbnailCreatorTask(videoThumbnail).execute(path) for every row
这是 ThumbnailCreatorTask:
private class ThumbnailCreatorTask extends AsyncTask<String, Void, Bitmap>{
private final WeakReference<ImageView> imageViewReference;
public ThumbnailCreatorTask(ImageView imageView){
imageViewReference = new WeakReference<ImageView>(imageView);
}
@Override
protected Bitmap doInBackground(String... params) {
return ThumbnailUtils.createVideoThumbnail(params[0], Thumbnails.MICRO_KIND);
}
@Override
protected void onPostExecute(Bitmap bitmap) {
if (imageViewReference != null && bitmap != null) {
ImageView imageView = imageViewReference.get();
imageView.setImageBitmap(bitmap);
}
}
}
创建一些行后,我遇到以下崩溃:
07-16 16:26:30.060: E/dalvikvm-heap(17318): 1843200-byte external allocation too large for this process.
07-16 16:26:30.060: E/GraphicsJNI(17318): VM won't let us allocate 1843200 bytes
07-16 16:26:30.190: E/ThumbnailUtils(17318): Got OOM error
07-16 16:26:30.190: E/ThumbnailUtils(17318): java.lang.OutOfMemoryError: bitmap size exceeds VM budget
07-16 16:26:30.190: E/ThumbnailUtils(17318): at android.graphics.Bitmap.nativeCreate(Native Method)
07-16 16:26:30.190: E/ThumbnailUtils(17318): at android.graphics.Bitmap.createBitmap(Bitmap.java:477)
07-16 16:26:30.190: E/ThumbnailUtils(17318): at android.graphics.Bitmap.createBitmap(Bitmap.java:432)
07-16 16:26:30.190: E/ThumbnailUtils(17318): at android.media.MediaMetadataRetriever._getFrameAtTime(Native Method)
07-16 16:26:30.190: E/ThumbnailUtils(17318): at android.media.MediaMetadataRetriever.getFrameAtTime(MediaMetadataRetriever.java:201)
07-16 16:26:30.190: E/ThumbnailUtils(17318): at android.media.MediaMetadataRetriever.getFrameAtTime(MediaMetadataRetriever.java:225)
07-16 16:26:30.190: E/ThumbnailUtils(17318): at android.media.ThumbnailUtils.createVideoThumbnail(ThumbnailUtils.java:155)
正如我认为我的方法是完全错误的。在我的情况下应该如何处理缩略图创建?