bumptech / bumptech/glide

Restarting from first frame shows frame from previous run

Open
#4,144 1 comment 0 reactions 0 assignees View on GitHub
bug
Dominant language
Java
Stars
35k
Forks
6.2k
Avg merge
1d 11h
Merged PRs (30d)
8

Description

**Glide Version**:
4.11.0

**Integration libraries**:
None

**Device/Android Version**:
* Samsung S9
* Samsung A40
* Emulated Nexus 5X API 28

**Issue details / Repro steps / Use case background**:
*Issue details:*
When a Gif animation is started, then stopped, then restarted from its first frame, the animation does **not** cleanly start from first frame. Instead, for a split second one can see the last shown frame from previous run.
This is visible very very frequently, although not systematically. To be sure of what you see, it helps to capture a screen recording and then moving with a time slider in it.
Basically it seems the same issue experienced [here](https://github.com/bumptech/glide/issues/2052#issuecomment-498631402) by @Elliptica1 user, but no answer found there. Checked also issue #3445 , but no help from there as well.

*Repro steps:*
A repro project showing the issue is downloadable [here](https://drive.google.com/open?id=1GYO6Lf6ma61bsKmaL4ktIJ7FlrzcMiOK).

1. Press Show button to play the composed animation: intro starts from fully transparent area, then seamlessly joins with loop.
1. After some seconds press Hide.
1. Then again, press Show and you should see the intro starting from its last shown frame (the large circle, instead of fully transparent area). The loop as well might start from its last shown frame (you see a glitch between the intro and the loop, instead of a seamless joint).

You can repeat the process multiple times. The intro and loop parts have been visually marked with a dot in order to detect which is currently showing. Again, a screen recording helps. Here's an [example](https://drive.google.com/open?id=1ecJcK2TX7qFeUTZjGAMZCNSr9D7-r6NH).

*Use case background:*
To show (upon some event) a composed animation made by an intro GIF, played once, then followed by a looping GIF which keeps playing.
At some point (due to some event), looping animation will be stopped and hidden.
Later on, the same composed animation is started again, so first the intro plays from the beginning, then the loop plays from its beginning.
Intro animation must always start from its first frame, as well as loop animation must always start from its first frame, in order to give a visually seamless effect.
For sake of simplicity, repro project does not include fade, cross-fade and other effects that we might apply in our actual use case.

**Glide load line**:
Repro project [here](https://drive.google.com/open?id=1GYO6Lf6ma61bsKmaL4ktIJ7FlrzcMiOK) contains actual used code.

```java
RequestManager requestManager = Glide.with(context.getApplicationContext());

loopTarget = new MyCustomTarget(loopImageView, true, null);

requestManager
.asGif()
.load(LOOP_RES_ID)
.into(loopTarget);

/*
class MyCustomTarget extends ImageViewTarget
- stops resource, to prevent autoplay
- sets either 1 or infinite loop count
- registers animation callback, if any
*/
```

**`GlideModule`**:
```java
@GlideModule
public class RestartGifAppGlideModule extends AppGlideModule {
// needed for Glide library
}
```

**Layout XML**:
Repro project [here](https://drive.google.com/open?id=1GYO6Lf6ma61bsKmaL4ktIJ7FlrzcMiOK) contains actual used code.

```xml

```

ImageViews are added programmatically:

```java
private static int IMAGE_WIDTH = 750;
private static int IMAGE_HEIGHT = 750;

// upon activity onStart event:

loopImageView = new ImageView(context);
loopImageView.setTag("Loop");

loopImageView.setVisibility(View.GONE);
frameLayout.addView(loopImageView);

// upon frameLayout first onLayoutChange event:

FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(IMAGE_WIDTH, IMAGE_HEIGHT);

// center in container
layoutParams.leftMargin = (frameLayout.getWidth() - IMAGE_WIDTH) / 2;
layoutParams.topMargin = (frameLayout.getHeight() - IMAGE_HEIGHT) / 2;
layoutParams.rightMargin = 0;
layoutParams.bottomMargin = 0;

loopImageView.setLayoutParams(layoutParams);
```

**Stack trace / LogCat**:
There's no logged error involved.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.