Hi, I'm using Glide 4.0 RC1 and I dont know how to load a gif stopped at first with this version. At first, I only need the first frame of the gif. When I click on it, I want to animate it. And when the loop completes 3 times, I want to stop it and show a play button again. So I need to listen somehow when the loop ends.
I load my gif normally, and when onResourceReady() is invoked, I call resource.stop(), but it start playing the gif anyway.
My code looks like this:
RequestOptions options = new RequestOptions();
options.diskCacheStrategy(DiskCacheStrategy.AUTOMATIC);
RequestBuilder<GifDrawable> request = Glide.with(getContext()).asGif().apply(options)
.listener(new RequestListener<GifDrawable>() {
@Override public boolean onLoadFailed(@Nullable GlideException e, Object model,
Target<GifDrawable> target, boolean isFirstResource) { }
@Override public boolean onResourceReady(GifDrawable resource, Object model,
Target<GifDrawable> target, DataSource dataSource, boolean isFirstResource) {
resource.setLoopCount(3);
resource.stop();
}
});
request.load(path).into(mImage);
Also, I dont know how to set a callback to be invoked when the gif finishes.
Thanks you so much.
I used the upstairs method. When I switched the GIF picture, it would flicker to the last frame of the GIF picture. Would there be any other way to control the number of GIF broadcasts? This is not the case with 3.7.0
the 3.7 version of the method
Glide.with(MainActivity.this).load(isDay ? R.drawable.day : R.drawable.night).into(new GlideDrawableImageViewTarget(img, 1));
In this version of Glide 4.0 RC1 how do you control the number of plays like this?
It would be really nice to have a GlideDrawableImageViewTarget in v4.0.
Nobody knows how to load a gif without animating it in 4.0 version?
@vicpinm just load it as a bitmap and it won't be animated :
Glide.with(ctx.getApplicationContext())
.asBitmap()
.load(urlmage)
.apply(options)
.into(new BitmapImageViewTarget(mImageView) {
@Override
public void onResourceReady(Bitmap resource, @Nullable Transition super Bitmap> transition) {
super.onResourceReady(resource, transition);
}
@Override
public void onLoadFailed(@Nullable Drawable errorDrawable) {
super.onLoadFailed(errorDrawable);
}
@Override
public void onLoadCleared(Drawable placeholder) { }
});
This issue has been automatically marked as stale because it has not had activity in the last seven days. It will be closed if no further activity occurs within the next seven days. Thank you for your contributions.
No answer?
You can extend DrawableImageViewTarget:
Glide.with(fragment)
.load(url)
.into(new DrawableImageViewTarget(imageView) {
@Override
public void onResourceReady(Drawable resource, Transition<? super Drawable> transition) {
if (resource instanceof GifDrawable) {
GifDrawable gifDrawable = (GifDrawable) resource;
// Do things with GIF here.
}
}
});
You could make that cleaner by extending ImageViewTarget as a new class that expects GifDrawables explicitly and then using the asGif() method so that the types match, but it should work either way.
Use onResourceReady is working partially.
The gif started playing again after the app returned to foreground state.
Looks like an intended behavior of Glide.
Updated
I figured it out later.
Just need to override the onStart().
@Override
public void onStart() {
// super.onStart();
}
Most helpful comment
It would be really nice to have a GlideDrawableImageViewTarget in v4.0.