Java 带有createVideoThumbnail的listview延迟
这是用于在listview中显示视频缩略图的自定义适配器类 我尝试将VideoFetcherTask添加到asyncTask中,但在滚动缩略图时继续更改,请帮助我,我还尝试在加载之前存储thumb的数据,但仍然遇到问题Java 带有createVideoThumbnail的listview延迟,java,android,listview,Java,Android,Listview,这是用于在listview中显示视频缩略图的自定义适配器类 我尝试将VideoFetcherTask添加到asyncTask中,但在滚动缩略图时继续更改,请帮助我,我还尝试在加载之前存储thumb的数据,但仍然遇到问题 public class VideoAdapter extends CursorAdapter { private Context mContext; private Cursor mCursor; public VideoAdapter(Contex
public class VideoAdapter extends CursorAdapter {
private Context mContext;
private Cursor mCursor;
public VideoAdapter(Context context, Cursor cursor){
super(context, cursor, 0);
mContext = context;
mCursor = cursor;
}
public void setData (Cursor data){
if (data != null) {
changeCursor(data);
notifyDataSetChanged();
}
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent){
return LayoutInflater.from(context).inflate(R.layout.video_item, parent, false);
}
public void bindView(View view, Context context, Cursor cursor){
TextView tvName = (TextView)view.findViewById(R.id.video_display_name);
final ImageView thumbnailView = (ImageView)view.findViewById(R.id.video_thumbnail);
String displayName = cursor.getString(cursor.getColumnIndexOrThrow(
MediaStore.Video.Media.DISPLAY_NAME
));
//todo remove code duplication - already exists in FileChooserActivity
final int column_index = cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA);
final String path = cursor.getString(column_index);
final Bitmap thumbnail = ThumbnailUtils.createVideoThumbnail(path, MediaStore.Images.Thumbnails.MINI_KIND);
tvName.setText(displayName);
thumbnailView.setContentDescription(displayName);
thumbnailView.setImageBitmap(thumbnail);
}
}
我是这样实现的。在获得一些权限后,我在创建时给空值,并执行videofetcher异步任务,以从设备及其工作区加载所有视频,但在滚动设备上的视频非常高
videoAdapter = new VideoAdapter(this, null);
videoList.setAdapter(videoAdapter);
VideoFetcherTask.execute(1,0);
public class VideoFetcherTask extends AsyncTask<Integer, Integer, Cursor>
{
private CursorLoader videoLoader;
String[] projections = {MediaStore.Video.Media._ID,
MediaStore.Video.Media.DATA,
MediaStore.Video.Media.DISPLAY_NAME,
MediaStore.Video.Media.SIZE};
protected void onPreExecute(){
videoLoader = new CursorLoader(FileChooserActivity.this, MediaStore.Video.Media.EXTERNAL_CONTENT_URI, projections,
null, // Return all rows
null, MediaStore.Files.FileColumns.DISPLAY_NAME + " DESC");
}
public Cursor doInBackground(Integer... params){
return videoLoader.loadInBackground();
}
@Override
protected void onPostExecute(Cursor cursor) {
super.onPostExecute(cursor);
videosCursor = cursor;
if (emptyVideoList != null) {
emptyVideoList.setVisibility(View.GONE);
}
videoAdapter.changeCursor(cursor);
videoAdapter.notifyDataSetChanged();
}
}
videoAdapter=新的videoAdapter(此为空);
videoList.setAdapter(videoAdapter);
VideoFetcherTask.execute(1,0);
公共类VideoFetcherTask扩展异步任务
{
私有游标加载程序视频加载程序;
字符串[]投影={MediaStore.Video.Media.\u ID,
MediaStore.Video.Media.DATA,
MediaStore.Video.Media.DISPLAY\u名称,
MediaStore.Video.Media.SIZE};
受保护的void onPreExecute(){
videoLoader=new CursorLoader(文件选择Activity.this、MediaStore.Video.Media.EXTERNAL\u CONTENT\u URI、投影、,
null,//返回所有行
null,MediaStore.Files.FileColumns.DISPLAY_NAME+“DESC”);
}
公共游标doInBackground(整数…参数){
返回videoLoader.loadInBackground();
}
@凌驾
受保护的void onPostExecute(游标){
super.onPostExecute(游标);
videosCursor=光标;
如果(emptyVideoList!=null){
emptyVideoList.setVisibility(View.GONE);
}
videoAdapter.changeCursor(光标);
videoAdapter.notifyDataSetChanged();
}
}
使用图像加载库,如毕加索,可以异步生成视频缩略图。所以请使用Glide或毕加索。还有一些简单的API也可以作为媒介。谢谢Glide正在使用iTunes的图像加载库,比如毕加索,它可以异步生成视频缩略图。所以请使用Glide或毕加索。也有一些简单的API作为媒介。谢谢Glide正在使用它