Unable to play GIF when I load it second time
See original GitHub issueDescription
I am loading gifs onto an ImageView. User is able to replace the loaded gif with another one.
Following is the code I use to initialize Coil singleton:
val imageLoader = ImageLoader.Builder(context)
.availableMemoryPercentage(0.25)
.crossfade(true) // or not
.componentRegistry {
// video-support
add(VideoFrameFileFetcher(context))
add(VideoFrameUriFetcher(context))
// gif-support
if (SDK_INT >= 28) {
add(ImageDecoderDecoder())
} else {
add(GifDecoder())
}
}
.logger(DebugLogger(Log.VERBOSE))
.build()
Coil.setImageLoader(imageLoader)
Following is the code I use to load the gif. (result=plays successfully)
// file = /storage/emulated/0/somelongpath/6421dc5e-c349-4f1b-b3ff-e5fad0e79e6e
binding.imageView.load(file)
// I/RealImageLoader: 💾 Successful (DISK) - /storage/emulated/0/somelongpath/6421dc5e-c349-4f1b-b3ff-e5fad0e79e6e
// V/RealBitmapPool: Missing bitmap=[193600]
// V/RealBitmapPool: Get bitmap=[193600]
// Hits=0, misses=1, puts=0, evictions=0, currentSize=0, maxSize=0, strategy=SizeStrategy: entries=LinkedMultimap( {193600:0} ), sizes={}
User chose a new gif file to replace. (result=loads thumbnail, but doesn’t play)
// file = /storage/emulated/0/somelongpath/3f9377d2-5a3c-4965-a0d8-f12b7b8e0d2c
binding.imageView.load(file)
// I/RealImageLoader: 💾 Successful (DISK) - /storage/emulated/0/somelongpath/3f9377d2-5a3c-4965-a0d8-f12b7b8e0d2c
// V/RealBitmapPool: Missing bitmap=[541440]
// V/RealBitmapPool: Get bitmap=[541440]
// Hits=0, misses=2, puts=0, evictions=0, currentSize=0, maxSize=0, strategy=SizeStrategy: entries=LinkedMultimap( {541440:0}, {193600:0} ), sizes={}
This is happening every time. Even if I use different gifs to test this, result is the same. First time works. Second time doesn’t play. Third time works. Fourth and N times works.
Verified using DecodeUtils.isGif(source)
that both and all files are gif.
Expectation
Every call to load
plays the gif.
Present in 0.13.0
& 1.0.0-rc3
with gif and video support on “Android Emulator Pixel 3 API 29”
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (6 by maintainers)
Top Results From Across the Web
My animated GIF won't play - Microsoft Support
To do this, select the animated GIF file, and then on the View menu, click Preview/Properties. If the GIF does not play, try...
Read more >Troubleshoot Upload Failure - GIPHY support
If your uploads to GIPHY are not showing up on your channel page, it's a good idea to check a couple things before...
Read more >Animated GIFs Not Working In WordPress? Here's The Fix
There's a common issue in WordPress where animated GIFs don't seem to work properly. Usually the image shows up—but ... Your browser can't...
Read more >Firefox doesn't play animated gif properly (works fine in Chrome)
open firebug; load page; click on image twice; If you get a static sad face open firebug html ... The animation should then...
Read more >slideshow app for multiple animated gifs - Apple Community
Right now, I can show them one at a time. ... Photos can play a slideshow of GIFs, but it can't play a...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hey @colinrtwhite added PR for that issue. Sorry for delay, got caught up in stuff. By the way, issue reproducible in the sample app, you just need to switch to GIF tab, then open GIF twice. Second time GIF will not play.
Ok @colinrtwhite I poked around this issue and maybe you could give me some additional insight. So the problem essentially is that sometimes LifecycleRegistry can’t clear up previous observer (in this case ImageViewTarget) in time, causing it to reuse no longer valid object. This causes onStart callback to be never invoked, therefore animation on drawable is never started. My question is: do we really need objects of ImageViewTarget to be identified by wrapped ImageView? If I change:
to:
The problem seem to go away. Thoughts?