Android Open Source - MediaCodecVideoPlayer Load Thumbnail Task






From Project

Back to project page MediaCodecVideoPlayer.

License

The source code is released under:

Apache License

If you think the Android project MediaCodecVideoPlayer listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.jasonsoft.mediacodecvideoplayer;
/*ww  w.j a  va2s  .c om*/
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory.Options;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.AsyncTask;
import android.provider.MediaStore.Video;
import android.provider.MediaStore.Video.Thumbnails;
import android.view.View;
import android.widget.ImageView;

import com.jasonsoft.mediacodecvideoplayer.cache.CacheManager;
import com.jasonsoft.mediacodecvideoplayer.data.AsyncDrawable;
import com.jasonsoft.mediacodecvideoplayer.data.LoadThumbnailParams;
import com.jasonsoft.mediacodecvideoplayer.data.LoadThumbnailResult;

import java.lang.ref.WeakReference;

public class LoadThumbnailTask extends AsyncTask<LoadThumbnailParams, Void, LoadThumbnailResult> {
    private Context mContext;
    private final WeakReference<ImageView> thumbnailViewReference;
    private long data = 0;

    public LoadThumbnailTask(Context context, ImageView thumbnailView) {
        this.mContext = context;
        this.thumbnailViewReference = new WeakReference<ImageView>(thumbnailView);
    }

    @Override
    protected LoadThumbnailResult doInBackground(LoadThumbnailParams... params) {
        data = params[0].origId;
        Bitmap bitmap = Thumbnails.getThumbnail(mContext.getContentResolver(), data,
                Thumbnails.MINI_KIND, new Options());
        if (data > 0 && bitmap != null) {
            CacheManager.getInstance().addThumbnailToMemoryCache(String.valueOf(data), bitmap);
        }
        if (this.isCancelled()) { return null; }

        return new LoadThumbnailResult(bitmap);
    }

    @Override
    protected void onPostExecute(LoadThumbnailResult result) {
        if (isCancelled() || null == result) {
            return;
        }

        final ImageView thumbnailView = thumbnailViewReference.get();
        final LoadThumbnailTask loadThumbnailTask = getLoadThumbnailTask(thumbnailView);
        if (this == loadThumbnailTask && thumbnailView != null) {
            setThumbnail(result.bitmap, thumbnailView);
        }
    }

    public long getData() {
        return data;
    }
    /**
     * @param imageView Any imageView
     * @return Retrieve the currently active work task (if any) associated with this imageView.
     * null if there is no such task.
     */
    public static LoadThumbnailTask getLoadThumbnailTask(ImageView imageView) {
        if (imageView != null) {
            final Drawable drawable = imageView.getDrawable();
            if (drawable instanceof AsyncDrawable) {
                final AsyncDrawable asyncDrawable = (AsyncDrawable) drawable;
                return asyncDrawable.getLoadThumbnailTask();
            }
        }
        return null;
    }

    void setThumbnail(Bitmap bitmap, ImageView thumbnailView) {
        thumbnailView.setImageBitmap(bitmap);
        thumbnailView.setVisibility(View.VISIBLE);
    }

}




Java Source Code List

com.example.hellojni.HelloJni.java
com.jasonsoft.mediacodecvideoplayer.LoadThumbnailTask.java
com.jasonsoft.mediacodecvideoplayer.MediaCodecVideoPlayerActivity.java
com.jasonsoft.mediacodecvideoplayer.MenuDrawerBaseActivity.java
com.jasonsoft.mediacodecvideoplayer.RoundedCornerImageView.java
com.jasonsoft.mediacodecvideoplayer.Utils.java
com.jasonsoft.mediacodecvideoplayer.VideoSurfaceView.java
com.jasonsoft.mediacodecvideoplayer.adapter.MenuAdapter.java
com.jasonsoft.mediacodecvideoplayer.cache.CacheManager.java
com.jasonsoft.mediacodecvideoplayer.data.AsyncDrawable.java
com.jasonsoft.mediacodecvideoplayer.data.LoadThumbnailParams.java
com.jasonsoft.mediacodecvideoplayer.data.LoadThumbnailResult.java
com.jasonsoft.mediacodecvideoplayer.data.MenuDrawerCategory.java
com.jasonsoft.mediacodecvideoplayer.data.MenuDrawerItem.java
net.simonvt.menudrawer.BuildLayerFrameLayout.java
net.simonvt.menudrawer.ColorDrawable.java
net.simonvt.menudrawer.DraggableDrawer.java
net.simonvt.menudrawer.FloatScroller.java
net.simonvt.menudrawer.MenuDrawer.java
net.simonvt.menudrawer.NoClickThroughFrameLayout.java
net.simonvt.menudrawer.OverlayDrawer.java
net.simonvt.menudrawer.PeekInterpolator.java
net.simonvt.menudrawer.Position.java
net.simonvt.menudrawer.Scroller.java
net.simonvt.menudrawer.SinusoidalInterpolator.java
net.simonvt.menudrawer.SlideDrawable.java
net.simonvt.menudrawer.SlidingDrawer.java
net.simonvt.menudrawer.SmoothInterpolator.java
net.simonvt.menudrawer.StaticDrawer.java
net.simonvt.menudrawer.ViewHelper.java
net.simonvt.menudrawer.compat.ActionBarHelperCompat.java
net.simonvt.menudrawer.compat.ActionBarHelperNative.java
net.simonvt.menudrawer.compat.ActionBarHelper.java