skydoves / landscapist

🌻 A pluggable, highly optimized Jetpack Compose and Kotlin Multiplatform image loading library that fetches and displays network images with Glide, Coil, and Fresco.

Home Page:https://skydoves.github.io/landscapist/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to pause/resume webp animation?

rantianhua opened this issue · comments

Is your feature request related to a problem?

The following example shown us how to play an animation webp:

FrescoWebImage(
  controllerBuilder = {
      Fresco.newDraweeControllerBuilder()
          .setUri(poster.gif) // GIF or Webp image url.
          .setAutoPlayAnimations(true)
  },
  modifier = Modifier
    .fillMaxWidth()
    .height(300.dp)
)

Now I want to control the animation to pause/resume or start/stop the animation. I can make the parameter of setAutoPlayAnimations to be a remember field, however, FrescoWebImage will dismiss and show again, which is not smooth.

Describe the solution you'd like:

Provide a parameter to pause/resume the animation.

Hey @rantianhua, I believe you can pause and restart the animatable by adding this to your builder:

.setControllerListener(object : BaseControllerListener<ImageInfo>() {
    override fun onFinalImageSet(id: String?, imageInfo: ImageInfo?, animatable: Animatable?) {
      animatable?.stop()
      animatable?.start()
    }
  } 

@skydoves I tried this one, the webp won't be shown anymore if I do this

@skydoves I tried again and it worked, thanks

@rantianhua Happy to hear that!