Android Glide 获取视频某一帧的图片

/**
   * 加载第四秒的帧数作为封面
   *  url就是视频的地址
   */
  public static void loadCover(ImageView imageView, String url, Context context) {

      imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
      Glide.with(context)
              .setDefaultRequestOptions(
                      new RequestOptions()
                              .frame(4000000)
                              .centerCrop()
                              .error(R.mipmap.eeeee)//可以忽略
                              .placeholder(R.mipmap.ppppp)//可以忽略
              )
              .load(url)
              .into(imageView);
  }

public static void loadVideoScreenshot(final Context context, String uri, ImageView imageView, long frameTimeMicros) {
    RequestOptions requestOptions = RequestOptions.frameOf(frameTimeMicros);
    requestOptions.set(FRAME_OPTION, MediaMetadataRetriever.OPTION_CLOSEST);
    requestOptions.transform(new BitmapTransformation() {
        @Override
        protected Bitmap transform(@NonNull BitmapPool pool, @NonNull Bitmap toTransform, int outWidth, int outHeight) {
            return toTransform;
        }
        @Override
        public void updateDiskCacheKey(MessageDigest messageDigest) {
            try {
                messageDigest.update((context.getPackageName() + "RotateTransform").getBytes("utf-8"));
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
    Glide.with(context).load(uri).apply(requestOptions).into(imageView);
}

 

 

 

 

 

 

 

 

 

 

 

 

 

你可能感兴趣的:(Android Glide 获取视频某一帧的图片)