Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class GetThumbs extends AsyncTask<WeakHashMap<VideoFile, ImageView>, Object, Void> {
- @Override
- protected Void doInBackground(WeakHashMap<VideoFile, ImageView>[] weakHashMaps) {
- WeakHashMap<VideoFile, ImageView> weakHashMap = weakHashMaps[0];
- for (Map.Entry<VideoFile, ImageView> entry : weakHashMap.entrySet()) {
- File preview = new File(entry.getKey().thumbPath);
- if (!preview.exists()) { //creating preview thumbnails
- Bitmap thumbnail = ThumbnailUtils.createVideoThumbnail(entry.getKey().videoPath, MediaStore.Images.Thumbnails.MINI_KIND);
- try (FileOutputStream fos = new FileOutputStream(entry.getKey().thumbPath)) {
- thumbnail.compress(Bitmap.CompressFormat.PNG, 100, fos);
- } catch (Exception e) {
- Log.e(TAG, "output", e);
- }
- }
- publishProgress(entry.getKey().thumbPath, entry.getValue()); //setting preview to its imageview
- }
- return null;
- }
- @Override
- protected void onProgressUpdate(Object[] objects) {
- String path = (String) objects[0];
- ImageView image = (ImageView) objects[1];
- image.setImageBitmap(BitmapFactory.decodeFile(path));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement