Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GIF loading only first frame #2314

Closed
damionx7 opened this issue Jun 12, 2024 · 6 comments
Closed

GIF loading only first frame #2314

damionx7 opened this issue Jun 12, 2024 · 6 comments

Comments

@damionx7
Copy link

Describe the bug
I have added support for GIF loading using coil in my application. But only first frame is loaded, as can be seen in the video. When I click on the picture to start the animation again, then it fast forwards. While the gif loads normally in browser.

Logs/Screenshots

video6291576903329386898.mp4

Source Code


public class ImageUtils {

  private static volatile ImageUtils sInstance;
  private final ImageLoader mImageLoader;

  private ImageUtils(Context context) {
    ImageLoader.Builder builder = new ImageLoader.Builder(context)
        .crossfade(true)
        .error(R.drawable.placeholder)
        .placeholder(android.R.color.transparent)
        .components(getComponentRegistry(context));
    builder.eventListener(new EventListener() {
      @Override
      public void onSuccess(
          @NonNull ImageRequest request,
          @NonNull SuccessResult result) {
        Drawable drawable = result.getDrawable();
        //start gif animation
        if (drawable instanceof Animatable) {
          Timber.v("is-animatable");
          if (!((Animatable) drawable).isRunning()) {
            ((Animatable) drawable).start();
          }
        }
      }
    });
    if (BuildConfig.DEBUG) {
      builder.logger(new DebugLogger());
    }
    mImageLoader = builder.build();
  }

  public static void load(ImageView view, Object data) {
    if (data == null) {
      return;
    }
    ImageRequest.Builder builder = new ImageRequest.Builder(view.getContext()).data(data).target(view);
    ImageRequest request = builder.build();
    get(view.getContext()).getImageLoader().enqueue(request);
  }

  public static void clearCache(Context context) {
    try {
      get(context).getImageLoader().getMemoryCache().clear();
      get(context).getImageLoader().getDiskCache().clear();
    } catch (Exception ignored) {
      //
    }
  }

  public static ImageUtils get(Context context) {
    ImageUtils helper = sInstance;
    if (helper == null) {
      synchronized (ImageUtils.class) {
        helper = sInstance;
        if (helper == null) {
          sInstance = helper = new ImageUtils(context);
        }
      }
    }
    return helper;
  }

  private ComponentRegistry getComponentRegistry(Context context) {
    var builder = new ComponentRegistry.Builder()
        .add(new SvgDecoder.Factory())
        .add(SDK_INT >= VERSION_CODES.P ? new ImageDecoderDecoder.Factory(true) : new GifDecoder.Factory(true));
    return builder.build();
  }

  public ImageLoader getImageLoader() {
    return mImageLoader;
  }
}

@damionx7
Copy link
Author

download

This is the GIF

@colinrtwhite
Copy link
Member

colinrtwhite commented Jun 13, 2024

What version of Coil are you using? What device API level? This looks similar to this - can you see if your issue is still present in the latest snapshot?

@damionx7
Copy link
Author

Thanks for replying. I am using coil version 2.6.0. Device API is 34.
Its still stuck with latest snapshot version.

@colinrtwhite
Copy link
Member

@damionx7 Do you have a sample project that reproduces this? I tried loading the gif in the sample project in this repo and it animated as expected.

Screen_recording_20240626_104602.webm

@damionx7
Copy link
Author

Are you using the latest snapshot version ?

I have an application on play store that uses coil library for gif loading. https://play.google.com/store/apps/details?id=org.eu.thedoc.zettelnotes

@colinrtwhite
Copy link
Member

colinrtwhite commented Jun 28, 2024

I tested with 3.0.0-alpha07. Sorry, but it's not possible to investigate this without a way to reproduce it (it's not possible without source code). Feel free to reopen this issue with a sample project that reproduces the issue.

@colinrtwhite colinrtwhite closed this as not planned Won't fix, can't repro, duplicate, stale Jun 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants