我从sdcard获取视频网址列表并传递给适配器。在适配器中,从视频的URL创建缩略图位图。加载gridview变得非常慢,滚动也很慢。是否有任何方法可以更快速,更轻松地从SD卡中获取缩略图。
@Override
public View getView(int position, View convertView, ViewGroup parent) {
final ViewHolder holder;
if (convertView == null) {
convertView = infalter.inflate(R.layout.gallery_item, null);
holder = new ViewHolder();
holder.imgQueue = (ImageView) convertView.findViewById(R.id.imgQueue);
holder.imgQueueMultiSelected = (ImageView) convertView
.findViewById(R.id.imgQueueMultiSelected);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.imgQueue.setTag(position);
try {
Bitmap bitmap=ThumbnailUtils.createVideoThumbnail(data.get(position).sdcardPaththumbvideo, MediaStore.Video.Thumbnails.MINI_KIND);
if (bitmap==null) {
holder.imgQueue.setImageResource(R.drawable.no_media);
}
else{
holder.imgQueue.setImageBitmap(bitmap);
}
} catch (Exception e) {
e.printStackTrace();
}
return convertView;
}
答案 0 :(得分:1)
将ThumbnailUtils.createVideoThumbnail()
移出主应用程序线程。在this sample project中,我使用the SmartImageView library异步加载缩略图,在我的VideoThumbnailImage
上将我的自定义ViewBinder
应用为SimpleCursorAdapter
,显示查找所有视频的结果:
private static class ThumbnailBinder implements
SimpleCursorAdapter.ViewBinder {
@Override
public boolean setViewValue(View v, Cursor c, int column) {
if (column == c.getColumnIndex(MediaStore.Video.Media._ID)) {
VideoThumbnailImage thumb=
new VideoThumbnailImage(
c.getInt(column),
MediaStore.Video.Thumbnails.MICRO_KIND);
((SmartImageView)v).setImage(thumb,
R.drawable.ic_media_video_poster);
return(true);
}
return(false);
}
}
private static class VideoThumbnailImage implements SmartImage {
private int videoId;
private int thumbnailKind;
VideoThumbnailImage(int videoId, int thumbnailKind) {
this.videoId=videoId;
this.thumbnailKind=thumbnailKind;
}
@Override
public Bitmap getBitmap(Context ctxt) {
return(MediaStore.Video.Thumbnails.getThumbnail(ctxt.getContentResolver(),
videoId,
thumbnailKind,
null));
}
}