zjupure / GlideWebpDecoder

A Glide WebpDecoder Intergration Library for decoding and displaying webp images
Apache License 2.0
740 stars 91 forks source link

使用协程好像会出现多线程问题 #108

Closed RainlyTree closed 1 year ago

RainlyTree commented 1 year ago

viewScope.launch { val circleCrop: Transformation = CenterInside() val drawable = withContext(Dispatchers.IO) { Glide.with(context) .asDrawable() .load(url) .optionalTransform( WebpDrawable::class.java, WebpDrawableTransformation(circleCrop) ) .skipMemoryCache(true) .submit() .get() } val webpDrawable = drawable as? WebpDrawable webpDrawable?.loopCount = -1 webpDrawable?.start() withContext(Dispatchers.Main) { setImageDrawable(webpDrawable ?: drawable) } } 代码如上 这样加载的webp会出现每次播放第二遍播放到一半被重置 而且可能会出现com.bumptech.glide.integration.webp.decoder.WebpFrameLoader.onFrameReady (WebpFrameLoader.java:295)方法返回空的情况 是我哪里写的有问题吗

zjupure commented 1 year ago

Glide.with(context) 接口应该不支持在子线程调用,需要绑定View/Fragment的生命周期