Fresco: Animation stopped without onAnimationStop getting called

Created on 28 Mar 2018  路  7Comments  路  Source: facebook/fresco

Description

I want to hide simpleDraweeView after gif animation completion. So I have added AnimationListener and hide my controller onAnimationStop. But half of the time it does not call the onAnimationStop method.
Let me know if I am doing something wrong.

 new BaseControllerListener() {
        @Override
        public void onFinalImageSet(
          String id,
          @Nullable Object imageInfo,
          @Nullable final Animatable animatable) {
          if (animatable != null) {
            AnimatedDrawable2 animatedDrawable = (AnimatedDrawable2) animatable;
            animatedDrawable.setAnimationListener(new AnimationListener() {
              @Override
              public void onAnimationStart(AnimatedDrawable2 drawable) {

                Log.i(TAG, "onAnimationStart: ");
              }

              @Override
              public void onAnimationStop(AnimatedDrawable2 drawable) {
                .setVisibility(View.GONE);
                Log.i(TAG, "onAnimationStop: ");
              }

              @Override
              public void onAnimationReset(AnimatedDrawable2 drawable) {
                Log.i(TAG, "onAnimationReset: ");
              }

              @Override
              public void onAnimationRepeat(AnimatedDrawable2 drawable) {
                Log.i(TAG, "onAnimationRepeat: ");
              }

              @Override
              public void onAnimationFrame(AnimatedDrawable2 drawable, int frameNumber) {
                Log.i(TAG, "onAnimationFrame: "+frameNumber);
              }
            });
            Log.i(TAG, "animatable.start();: ");
            animatable.start();
          }
        }
      })

Additional Information

bug help wanted starter-task

All 7 comments

Could you share the code where you set up your ImageRequest and DraweeController?

Also CC @oprisnik

@foghina I am loading gif from resource folder.

ImageRequest imageRequest = ImageRequestBuilder.newBuilderWithResourceId(R.raw.mobile_confiti).build();
    DraweeController controller = Fresco.newDraweeControllerBuilder()
      .setUri(imageRequest.getSourceUri())
      .setAutoPlayAnimations(false)
      .setControllerListener(myBaseControllerListener) .build();

Same problem here. Animation stopped without onAnimationStop getting called. Version 1.8.1

Can't reproduce right now.
@PalDhv, can you please share your gif?
@test01wrk can you please share your code and gif?

@defHLT
gif file and logcat

I have 2 gif images, when the first one stopped, the other one shall start. But sometimes onAnimationStop isn't getting called, thus I can't start the next animator.

This is how I setup.

AbstractDraweeControllerBuilder controllerBuilder = Fresco.newDraweeControllerBuilder();
ImageRequest[] imageRequests = new ImageRequest[] { ImageRequestBuilder.newBuilderWithSource(uri).build()};
controllerBuilder.setFirstAvailableImageRequests(imageRequests, true);
controllerBuilder.setControllerListener(new BaseControllerListener() {
    @Override
    public void onFinalImageSet(String id, Object imageInfo, Animatable animatable) {
        AnimatedDrawable2 animator = (AnimatedDrawable2) animatable;
        animator.setAnimationListener(new BaseAnimationListener() {
            @Override
            public void onAnimationStop(AnimatedDrawable2 animatedDrawable2) {
                startNextAnim();
            }
        });
        AnimationBackend animationBackend = animator.getAnimationBackend();
        animator.setAnimationBackend(new AnimationBackendDelegate<AnimationBackend>(animationBackend) {
            @Override
            public int getLoopCount() {
                return 1; // only play once
            }
        });
        startFirstAnim();
    }
});
AbstractDraweeController draweeController = controllerBuilder.setOldController(draweeView.getController())
        .setAutoPlayAnimations(false).build();
draweeView.setController(draweeController);

The log of DrawListener shows that when the last draw finished, the animator was still running, somehow (frameNumberToDraw == FrameScheduler.FRAME_NUMBER_DONE) returned false.

05-19 17:37:54.504 onFinalImageSet: animatedDrawable=237593914, getFrameCount=89, getLoopCount=1, getLoopDurationMs=2670
05-19 17:37:54.510 onFinalImageSet: animatedDrawable=208633672, getFrameCount=25, getLoopCount=1, getLoopDurationMs=3000
...
05-19 17:38:45.769 onDraw: animatedDrawable=237593914, frameNumberToDraw=87, frameDrawn=true, isAnimationRunning=true, animationStartTimeMs=1496533, animationTimeMs=2613, lastFrameAnimationTimeMs=2595, actualRenderTimeStartMs=1499146, actualRenderTimeEndMs=1499147, startRenderTimeForNextFrameMs=2640, scheduledRenderTimeForNextFrameMs=2648
05-19 17:38:45.803 onDraw: animatedDrawable=237593914, frameNumberToDraw=88, frameDrawn=true, isAnimationRunning=true, animationStartTimeMs=1496533, animationTimeMs=2648, lastFrameAnimationTimeMs=2613, actualRenderTimeStartMs=1499181, actualRenderTimeEndMs=1499182, startRenderTimeForNextFrameMs=2670, scheduledRenderTimeForNextFrameMs=2678
05-19 17:38:45.836 onDraw: animatedDrawable=237593914, frameNumberToDraw=88, frameDrawn=true, isAnimationRunning=false, animationStartTimeMs=1496533, animationTimeMs=2681, lastFrameAnimationTimeMs=2648, actualRenderTimeStartMs=1499214, actualRenderTimeEndMs=1499215, startRenderTimeForNextFrameMs=-1, scheduledRenderTimeForNextFrameMs=-1
0...
05-19 17:38:48.623 onDraw: animatedDrawable=208633672, frameNumberToDraw=23, frameDrawn=true, isAnimationRunning=true, animationStartTimeMs=1499227, animationTimeMs=2774, lastFrameAnimationTimeMs=2656, actualRenderTimeStartMs=1502001, actualRenderTimeEndMs=1502001, startRenderTimeForNextFrameMs=2880, scheduledRenderTimeForNextFrameMs=2888
05-19 17:38:48.741 onDraw: animatedDrawable=208633672, frameNumberToDraw=24, frameDrawn=true, isAnimationRunning=true, animationStartTimeMs=1499227, animationTimeMs=2892, lastFrameAnimationTimeMs=2774, actualRenderTimeStartMs=1502119, actualRenderTimeEndMs=1502120, startRenderTimeForNextFrameMs=3000, scheduledRenderTimeForNextFrameMs=3008
05-19 17:38:48.860 onDraw: animatedDrawable=208633672, frameNumberToDraw=24, frameDrawn=true, isAnimationRunning=false, animationStartTimeMs=1499227, animationTimeMs=3011, lastFrameAnimationTimeMs=2892, actualRenderTimeStartMs=1502238, actualRenderTimeEndMs=1502239, startRenderTimeForNextFrameMs=-1, scheduledRenderTimeForNextFrameMs=-1
...
05-19 17:38:51.482 onDraw: animatedDrawable=237593914, frameNumberToDraw=87, frameDrawn=true, isAnimationRunning=true, animationStartTimeMs=1502243, animationTimeMs=2616, lastFrameAnimationTimeMs=2582, actualRenderTimeStartMs=1504859, actualRenderTimeEndMs=1504861, startRenderTimeForNextFrameMs=2640, scheduledRenderTimeForNextFrameMs=2648
05-19 17:38:51.516 onDraw: animatedDrawable=237593914, frameNumberToDraw=88, frameDrawn=true, isAnimationRunning=true, animationStartTimeMs=1502243, animationTimeMs=2650, lastFrameAnimationTimeMs=2616, actualRenderTimeStartMs=1504893, actualRenderTimeEndMs=1504895, startRenderTimeForNextFrameMs=2670, scheduledRenderTimeForNextFrameMs=2678
05-19 17:38:51.536 onDraw: animatedDrawable=237593914, frameNumberToDraw=88, frameDrawn=true, isAnimationRunning=true, animationStartTimeMs=1502243, animationTimeMs=2669, lastFrameAnimationTimeMs=2650, actualRenderTimeStartMs=1504912, actualRenderTimeEndMs=1504914, startRenderTimeForNextFrameMs=-1, scheduledRenderTimeForNextFrameMs=-1
// the log stopped here,  isAnimationRunning=true, onAnimationStop not called

@PalDhv and @test01wrk, thank you for this, but I'm still not able to reproduce it on my side. If you could provide a sample project with this bug, that would be awesome and I would take a look at it.

I'm closing this for now since we cannot reproduce this issue. If you can provide a sample project or reproduce in our Showcase sample app, we can re-open this issue.

Was this page helpful?
0 / 5 - 0 ratings