简体   繁体   English

我怎么知道在Fresco中完成Webp / Gif动画的时间

[英]How do I know when a Webp/Gif animation has completed in Fresco

I am using the following code to display a Gif, and I need a callback to know when the Webp/Gif animation has completed: 我使用以下代码来显示Gif,我需要一个回调来知道Webp / Gif动画何时完成:

DraweeController controller = Fresco.newDraweeControllerBuilder()
    .setUri(uri)
    .setAutoPlayAnimations(true)
    .build();
mSimpleDraweeView.setController(controller);

This was added in Fresco version 1.4.0 + which includes a new implementation for animated GIFs and animated WebPs. 这是在Fresco 1.4.0 +版本中添加的,其中包括动画GIF和动画WebP的新实现。

According to the solution to Fresco issue#181 , you set a ControllerListener and attach an animation listener: 根据Fresco 问题#181解决方案 ,您设置了一个ControllerListener并附加了一个动画监听器:

DraweeController controller = Fresco.newDraweeControllerBuilder()
    .setUri(uri)
    .setAutoPlayAnimations(true)
    .setControllerListener(new BaseControllerListener() {
        @Override
        public void onFinalImageSet(String id, @Nullable Object imageInfo, @Nullable Animatable animation) {
            if (animation != null) {
                AnimatedDrawable2 animatedDrawable = (AnimatedDrawable2) animation;
                animatedDrawable.setAnimationListener(new AnimationListener() {
                    @Override
                    public void onAnimationStart(AnimatedDrawable2 drawable) {
                        //
                    }

                    @Override
                    public void onAnimationStop(AnimatedDrawable2 drawable) {
                        // Called when the animation is stopped for the given drawable.
                        // Unless you manually stop the animation, this is where you get notified the animation has "completed".
                    }

                    @Override
                    public void onAnimationReset(AnimatedDrawable2 drawable) {
                        //
                    }

                    @Override
                    public void onAnimationRepeat(AnimatedDrawable2 drawable) {
                        //
                    }

                    @Override
                    public void onAnimationFrame(AnimatedDrawable2 drawable, int frameNumber) {
                        //
                    }
                });
            }
        }
    })
    .build();
mSimpleDraweeView.setController(controller);

And these are the dependencies in the build.gradle (Module level): 这些是build.gradle (模块级别)中的依赖项:

// Fresco
implementation 'com.facebook.fresco:fresco:1.11.0'

// For animated GIF support
implementation 'com.facebook.fresco:animated-gif:1.11.0'

// For WebP support, including animated WebP
implementation 'com.facebook.fresco:animated-webp:1.11.0'
implementation 'com.facebook.fresco:webpsupport:1.11.0'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM