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

时间:2016-06-20 07:41:48

标签: android animated-gif fresco

我使用以下代码显示Gif,我需要回调才能知道Webp / Gif动画何时完成:

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

1 个答案:

答案 0 :(得分:0)

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

根据壁画solutionissue#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'