1

I'm trying to use the following code which I found from here to save thumbnail of a video at a specific time, but VideoBitmapDecoder doesn't accept int parameter. It only accepts Context or BitmapPool. What should I do?

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);
Zoe
  • 27,060
  • 21
  • 118
  • 148
Javad
  • 147
  • 1
  • 10

1 Answers1

3

Root cause: From Glide v4 they changed APIs so I will give you 2 options to solve your problem.

Option 1: Keep the current code and change Glide dependencies version in app.gradle file.

// 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'

Option 2: Keep the current Glide dependencies in app.gradle file and change your code.

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);

Update: If you want to process bitmap not display on a view

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();
Son Truong
  • 13,661
  • 5
  • 32
  • 58