Skip to content

Instantly share code, notes, and snippets.

@markcadag
Last active March 6, 2019 14:29
Show Gist options
  • Save markcadag/a88a11bb297537491f9b92a46be719d4 to your computer and use it in GitHub Desktop.
Save markcadag/a88a11bb297537491f9b92a46be719d4 to your computer and use it in GitHub Desktop.
Enable pause and play gif using glide 4.0
Glide.with(holder.itemView)
.asBitmap()
.load("http://i.imgur.com/VuItY0T.gif")
.into(holder.imageContent)
val playPauseGif = PlayPauseGif(holder.imageContent)
holder.imageContent.setOnClickListener{
if (playPauseGif.isPlaying()) {
Log.e(TAG, "pausing")
playPauseGif.pause()
} else {
Log.e(TAG, "playing")
playPauseGif.play()
Glide.with(holder.itemView)
.load("http://i.imgur.com/VuItY0T.gif")
.into(playPauseGif)
}
}
class PlayPauseGif(view: ImageView ? ): DrawableImageViewTarget(view) {
var gif: GifDrawable ? = null
override fun onResourceReady(resource: Drawable, transition: Transition < in Drawable > ? ) {
if (resource is GifDrawable) {
gif = resource
}
super.onResourceReady(resource, transition)
}
fun isPlaying(): Boolean {
gif?.let {
return it.isRunning
}
return false
}
fun play() {
gif?.start()
}
fun pause() {
gif?.stop()
}
}
@MarkJoelSingma
Copy link

Thank you so my good sir.

@mig15
Copy link

mig15 commented Aug 18, 2018

not working, onResourceReady never called

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment