bumptech / bumptech/glide

Load Gif without animating it in 4.0

Open
#2,109 9 comments 0 reactions 0 assignees View on GitHub
documentation
Dominant language
Java
Stars
35k
Forks
6.2k
Avg merge
1d 11h
Merged PRs (30d)
8

Description

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 request = Glide.with(getContext()).asGif().apply(options)
.listener(new RequestListener() {

@Override public boolean onLoadFailed(@Nullable GlideException e, Object model,
Target target, boolean isFirstResource) { }

@Override public boolean onResourceReady(GifDrawable resource, Object model,
Target 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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.