-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to set loopcount for AnimatedImage after v1.4.0? #1863
Labels
Comments
Ideally, your GIF would be properly formatted and have the loop count set to N. Otherwise, you can create a modifying backend, something like this: public class LoopCountModifyingBackend extends AnimationBackendDelegate {
private int mLoopCount;
public LoopCountModifyingBackend(
@Nullable AnimationBackend animationBackend,
int loopCount) {
super(animationBackend);
mLoopCount = loopCount;
}
@Override
public int getLoopCount() {
return mLoopCount;
}
} and then set it to your animated drawable: final DraweeController controller = Fresco.newDraweeControllerBuilder()
.setAutoPlayAnimations(true)
.setUri(uri)
.setControllerListener(new BaseControllerListener<ImageInfo>() {
@Override
public void onFinalImageSet(
String id,
@Nullable ImageInfo imageInfo,
@Nullable Animatable animatable) {
if (animatable instanceof AnimatedDrawable2) {
AnimatedDrawable2 animatedDrawable = (AnimatedDrawable2) animatable;
animatedDrawable.setAnimationBackend(new LoopCountModifyingBackend(animatedDrawable.getAnimationBackend(), 3));
}
}
})
.build();
simpleDraweeView.setController(controller); You can also create a custom DrawableFactory that does this directly and then pass it when the image is rendered via PipelineDraweeController. |
Thanks. |
now for fresco 2.0.0+ ,how to do this? |
works very well! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Now I aim to play a gif image 5 time.
And I found there is a method getLoopCount for get the number of loops for a animatedImage,
but the question is I don't know how to dynamic set loopCount.
Waiting for your help.
The text was updated successfully, but these errors were encountered: