How to create thumbnail of video url form server

Try this Create new AsyncTask like this

public class DownloadImage extends AsyncTask<String, Void, Bitmap> {
    ImageView bmImage;

    public DownloadImage(ImageView bmImage) {
        this.bmImage = (ImageView ) bmImage;
    }

    protected Bitmap doInBackground(String... urls) {
        Bitmap myBitmap = null;
        MediaMetadataRetriever mMRetriever = null;
        try {
            mMRetriever = new MediaMetadataRetriever();
            if (Build.VERSION.SDK_INT >= 14)
                mMRetriever.setDataSource(urls[0], new HashMap<String, String>());
            else
                mMRetriever.setDataSource(urls[0]);
            myBitmap = mMRetriever.getFrameAtTime();
        } catch (Exception e) {
            e.printStackTrace();


        } finally {
            if (mMRetriever != null) {
                mMRetriever.release();
            }
        }
        return myBitmap;
    }

    protected void onPostExecute(Bitmap result) {
        bmImage.setImageBitmap(result);
    }
}

Than call this AsyncTask like this

   new DownloadImage(YourImageView).execute("Your URL");

EDIT

Or you can also use Glide to create thumbnail of video from url

 RequestOptions requestOptions = new RequestOptions();
 requestOptions.placeholder(R.drawable.placeholder_card_view);
 requestOptions.error(R.drawable.placeholder_card_view);


  Glide.with(getContext())
       .load(path)
       .apply(requestOptions)
       .thumbnail(Glide.with(getContext()).load(path))
       .into(ivVideoThumbnail);

Leave a Comment