Advertisement
HenX

Untitled

Dec 27th, 2014
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.17 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() {
  15.     }
  16.  
  17.     public void SetImageView(ImageView imageView) {
  18.         this.imageView = imageView;
  19.     }
  20.  
  21.     @Override
  22.     protected Bitmap doInBackground(SyncFile... params) {
  23.         SyncFile file = (SyncFile) params[0];
  24.         //
  25.         Bitmap bitmap;
  26.         final BitmapFactory.Options options = new BitmapFactory.Options();
  27.         options.inSampleSize = 8;
  28.  
  29.         Log.d("AsyncFiles", "Setting bitmap for " + file.name);
  30.  
  31.         if (file.name.contains(".mp4")) {
  32.             MediaMetadataRetriever mediaMetadataRetriever = new MediaMetadataRetriever();
  33.             mediaMetadataRetriever.setDataSource(file.path);
  34.             bitmap = mediaMetadataRetriever.getFrameAtTime(1 * 1000);
  35.         } else {
  36.             bitmap = BitmapFactory.decodeFile(file.path, options);
  37.         }
  38.         return bitmap;
  39.     }
  40.  
  41.     @Override
  42.     protected void onPostExecute(Bitmap bitmap) {
  43.         imageView.setImageBitmap(bitmap);
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement