我想从服务器获取更多的10个视频缩略图到Android中的图像视图。现在,我可以成功地将缩略图的视频显示到图像视图中,但是我的问题是显示所有缩略图需要花费太多时间。所以它显示空白黑屏直到它加载所有缩略图。如何使用asynctask加载图像缩略图android
,所以我决定的AsyncTask该节目的进度条使用,直到它加载的所有小样的,但它并不显示进度条都没有。所以任何想法如何解决这个问题。
代码
ImageView video_one, video_two, video_three, video_four, video_five;
ImageView video_six, video_seven, video_eight, video_nine, video_ten;
ImageView video_ele, video_twe, video_thir, video_fort, video_fif;
String path = "http://serverlink/Fidol/upload/test.mp4";
String path1 = "http://serverlink/Fidol/upload/ABCD.mp4";
String path2 = "http://serverlink/Fidol/upload/bean.mp4";
String path3 = "http://serverlink/Fidol/upload/masti.mp4";
String path4 = "http://serverlink/Fidol/upload/ben.mp4";
Bitmap bm = ThumbnailUtils.createVideoThumbnail(path,
MediaStore.Images.Thumbnails.MICRO_KIND);
Bitmap bm1 = ThumbnailUtils.createVideoThumbnail(path1,
MediaStore.Images.Thumbnails.MICRO_KIND);
Bitmap bm2 = ThumbnailUtils.createVideoThumbnail(path2,
MediaStore.Images.Thumbnails.MICRO_KIND);
Bitmap bm3 = ThumbnailUtils.createVideoThumbnail(path3,
MediaStore.Images.Thumbnails.MICRO_KIND);
Bitmap bm4 = ThumbnailUtils.createVideoThumbnail(path4,
MediaStore.Images.Thumbnails.MICRO_KIND);
然后我呼吁
new loadThumbnail().execute();
这里是我的AsyncTask类
class loadThumbnail extends AsyncTask<String, String, String> {
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(ShowVideo.this);
pDialog.setMessage("Loading Videos... Please wait...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();
}
protected String doInBackground(String... args) {
video_one.setImageBitmap(bm);
video_two.setImageBitmap(bm1);
video_three.setImageBitmap(bm2);
video_four.setImageBitmap(bm3);
video_five.setImageBitmap(bm4);
video_six.setImageBitmap(bm);
video_seven.setImageBitmap(bm1);
video_eight.setImageBitmap(bm2);
video_nine.setImageBitmap(bm3);
video_ten.setImageBitmap(bm4);
video_ele.setImageBitmap(bm);
video_twe.setImageBitmap(bm1);
video_thir.setImageBitmap(bm2);
video_fort.setImageBitmap(bm3);
video_fif.setImageBitmap(bm4);
return null;
}
protected void onPostExecute(String file_url) {
pDialog.dismiss();
}
}
使用延迟加载与UIL http://stackoverflow.com/questions/16789676/caching - 图像和显示 – Raghunandan
@Raghunandan,谢谢,但我没有列表视图以及任何自定义类在这种情况下,我如何使用您的答案请帮助。我只有几个图像视图,我想要显示视频缩略图,直到它加载它应该显示进度条。而已。 – InnocentKiller
你不能从backgroudn线程更新UI,你在doinbackground中设置位图是不可能的。我认为你使用listview更好。在链接你从服务器获取图像你从mediastore – Raghunandan