Advertisement
Guest User

Untitled

a guest
Jan 10th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.28 KB | None | 0 0
  1. public class GetThumbs extends AsyncTask<WeakHashMap<VideoFile, ImageView>, Object, Void> {
  2.  
  3.     @Override
  4.     protected Void doInBackground(WeakHashMap<VideoFile, ImageView>[] weakHashMaps) {
  5.         WeakHashMap<VideoFile, ImageView> weakHashMap = weakHashMaps[0];
  6.         for (Map.Entry<VideoFile, ImageView> entry : weakHashMap.entrySet()) {
  7.             File preview = new File(entry.getKey().thumbPath);
  8.             if (!preview.exists()) {  //creating preview thumbnails
  9.                 Bitmap thumbnail = ThumbnailUtils.createVideoThumbnail(entry.getKey().videoPath, MediaStore.Images.Thumbnails.MINI_KIND);
  10.                 try (FileOutputStream fos = new FileOutputStream(entry.getKey().thumbPath)) {
  11.                     thumbnail.compress(Bitmap.CompressFormat.PNG, 100, fos);
  12.                 } catch (Exception e) {
  13.                     Log.e(TAG, "output", e);
  14.                 }
  15.             }
  16.             publishProgress(entry.getKey().thumbPath, entry.getValue()); //setting preview to its imageview
  17.  
  18.         }
  19.         return null;
  20.     }
  21.  
  22.     @Override
  23.     protected void onProgressUpdate(Object[] objects) {
  24.         String path = (String) objects[0];
  25.         ImageView image = (ImageView) objects[1];
  26.         image.setImageBitmap(BitmapFactory.decodeFile(path));
  27.     }
  28.  
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement