Advertisement
HenX

AsyncTask

Dec 27th, 2014
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.14 KB | None | 0 0
  1. package com.example.cloudzwi0009;
  2.  
  3. import android.graphics.Bitmap;
  4. import android.graphics.BitmapFactory;
  5. import android.media.MediaMetadataRetriever;
  6. import android.os.AsyncTask;
  7. import android.util.Log;
  8. import android.widget.ImageView;
  9.  
  10. public class ImageLoader extends AsyncTask<SyncFile, Void, Bitmap> {
  11.    
  12.     private ImageView imageView;
  13.  
  14.     public ImageLoader(ImageView imageView) {
  15.         this.imageView = imageView;
  16.     }
  17.  
  18.     @Override
  19.     protected Bitmap doInBackground(SyncFile... params) {
  20.         SyncFile file = (SyncFile) params[0];
  21.         //
  22.         Bitmap bitmap;
  23.         final BitmapFactory.Options options = new BitmapFactory.Options();
  24.         options.inSampleSize = 16;
  25.  
  26.         Log.d("AsyncFiles","Setting bitmap for " + file.name);
  27.        
  28.         if (file.name.contains(".mp4")) {
  29.             MediaMetadataRetriever mediaMetadataRetriever = new MediaMetadataRetriever();
  30.             mediaMetadataRetriever.setDataSource(file.path);
  31.             bitmap = mediaMetadataRetriever.getFrameAtTime(1 * 1000);
  32.         } else {
  33.             bitmap = BitmapFactory.decodeFile(file.path, options);
  34.         }
  35.         return bitmap;
  36.     }
  37.  
  38.     @Override
  39.     protected void onPostExecute(Bitmap bitmap) {
  40.         imageView.setImageBitmap(bitmap);  
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement