如何知道在Fresco中Webp/GIF动画何时完成

3
我使用以下代码来显示GIF,我需要一个回调函数来知道Webp / GIF动画何时完成:
DraweeController controller = Fresco.newDraweeControllerBuilder()
    .setUri(uri)
    .setAutoPlayAnimations(true)
    .build();
mSimpleDraweeView.setController(controller);
1个回答

0

这是在Fresco 1.4.0版本中添加的,其中包括用于动画GIF和动画WebP的新实现。

根据solution解决方案到Fresco issue#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);

这些是在 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'

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接