Reputation: 5234
I am trying to get thumbnail of more then 10 videos from server to Image-view in android. Now i am successfully able to display thumbnail's of videos into image-view but my problem is it is taking too much time to display all thumbnail's. So it is showing blank black screen till it load all thumbnail's.
So i decided to use Asynctask that show's progress bar till it load's all thumbnail's but it doesn't show progress bar at all. So any idea how to solve this issue.
Code
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);
then i have called
new loadThumbnail().execute();
and here is my asynctask class
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();
}
}
Upvotes: 0
Views: 1627
Reputation: 10768
This might help:
class SetThumb extends AsyncTask<String, Void, Bitmap>{
private ImageView imageView;
SetThumb(ImageView imageView){
this.imageView=imageView;
}
@Override
protected Bitmap doInBackground(String... strings) {
return ThumbnailUtils.createVideoThumbnail(strings[0],MediaStore.Video.Thumbnails.MICRO_KIND);
}
@Override
protected void onPostExecute(Bitmap thumb){
imageView.setImageBitmap(thumb);
}
}
NOW EXECUTE THIS TASK
new SetThumb(your_image_view).execute(path_of_file);
Upvotes: 0
Reputation: 2451
Try this
@Override
protected void onPreExecute() {
pDialog = new ProgressDialog(ShowVideo.this);
pDialog.setMessage("Loading Videos... Please wait...");
pDialog.show();
}
Also in your code if you have written loadThumbnail.get()
somewhere remove that too,as this will block the UI thread.
Upvotes: 0
Reputation: 4503
In AsyncTask there's a method callonProgressUpdate(Integer...)
which you can make use for progress updating.
Check this link
Upvotes: 0
Reputation: 5068
do this :
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);
in onPostExecute becuase you can not modify ui from doinbackground
and do this in doInbackground
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);
Upvotes: 1
Reputation: 763
I think you should put
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);
under the doInBackground
method because as far as I understand thats where the task is happening.
Upvotes: 0