coil-kt / coil

Image loading for Android and Compose Multiplatform.
https://coil-kt.github.io/coil/
Apache License 2.0
10.46k stars 640 forks source link

GIF loading only first frame #2314

Closed damionx7 closed 1 day ago

damionx7 commented 2 weeks ago

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

https://github.com/coil-kt/coil/assets/6530843/8e891632-38f2-438a-a033-a6a23bc0d77c

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 commented 2 weeks ago

download

This is the GIF

colinrtwhite commented 2 weeks ago

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 commented 2 weeks ago

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

colinrtwhite commented 2 days ago

@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 commented 1 day ago

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 commented 1 day ago

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.