VideoBitmapDecoder不接受int(Android-Glide)

时间:2018-08-18 17:33:46

标签: java android kotlin bitmap android-glide

我正在尝试使用从here中找到的以下代码在特定时间保存视频的缩略图,但是VideoBitmapDecoder不接受int参数。它仅接受Context或BitmapPool。我该怎么办?

BitmapPool bitmapPool = Glide.get(getApplicationContext()).getBitmapPool(); 
int microSecond = 6000000;// 6th second as an example 
VideoBitmapDecoder videoBitmapDecoder = new VideoBitmapDecoder(microSecond); 
FileDescriptorBitmapDecoder fileDescriptorBitmapDecoder = new FileDescriptorBitmapDecoder(videoBitmapDecoder, bitmapPool, DecodeFormat.PREFER_ARGB_8888); 
Glide.with(getApplicationContext()) .load(yourUri)
  .asBitmap()
  .override(50,50)//
  .videoDecoder(fileDescriptorBitmapDecoder)       .into(yourImageView);

1 个答案:

答案 0 :(得分:2)

根本原因:他们从Glide v4更改了API,因此我将为您提供2个解决问题的选项。

选项1:保留当前代码,并在app.gradle文件中更改Glide依赖项版本。

// implementation 'com.github.bumptech.glide:glide:4.8.0'
// annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0'
implementation 'com.github.bumptech.glide:glide:3.8.0'
annotationProcessor 'com.github.bumptech.glide:compiler:3.8.0'

选项2:将当前的Glide依赖项保留在app.gradle文件中并更改代码。

int microSecond = 6000000;// 6th second as an example
RequestOptions options = new RequestOptions().frame(microSecond).override(50, 50);

Glide.with(getApplicationContext())
        .asBitmap()
        .load(videoUri)
        .apply(options)
        .into(yourImageView);

更新:如果要处理的位图未显示在视图上

Glide.with(getApplicationContext())
                .asBitmap()
                .load(videoUri)
                .apply(options)
                .listener(new RequestListener<Bitmap>() {
                    @Override
                    public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Bitmap> target, boolean isFirstResource) {
                        return false;
                    }

                    @Override
                    public boolean onResourceReady(Bitmap bitmap, Object model, Target<Bitmap> target, DataSource dataSource, boolean isFirstResource) {
                        // TODO: Process your bitmap here
                        return false;
                    }
                })
                .submit();