Fix animated webp playback (#8120)

* fix: add webp as playable image type

* fix: make glide transformations optional to prevent rendering webp throwing exception

* fix: stop marking webp as playable by default

* fix: play animated Webp in attachment view

* feat: autoplay webp if autoplay is enabled

---------

Signed-off-by: Alex Maras <dev@alexmaras.com>
Co-authored-by: Jorge Martín <jorgem@element.io>
This commit is contained in:
Alex Maras 2023-05-26 23:03:24 +08:00 committed by GitHub
parent 8f69e411d7
commit 24b18847b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 10 additions and 6 deletions

1
changelog.d/8120.feature Normal file
View File

@ -0,0 +1 @@
Marks WebP files as Animated and allows them to play

View File

@ -30,6 +30,7 @@ object MimeTypes {
const val BadJpg = "image/jpg" const val BadJpg = "image/jpg"
const val Jpeg = "image/jpeg" const val Jpeg = "image/jpeg"
const val Gif = "image/gif" const val Gif = "image/gif"
const val Webp = "image/webp"
const val Ogg = "audio/ogg" const val Ogg = "audio/ogg"

View File

@ -528,6 +528,8 @@ class MessageItemFactory @Inject constructor(
) )
val playable = messageContent.mimeType == MimeTypes.Gif val playable = messageContent.mimeType == MimeTypes.Gif
// don't show play button because detecting animated webp isn't possible via mimetype
val playableIfAutoplay = playable || messageContent.mimeType == MimeTypes.Webp
return MessageImageVideoItem_() return MessageImageVideoItem_()
.attributes(attributes) .attributes(attributes)
@ -549,7 +551,7 @@ class MessageItemFactory @Inject constructor(
} }
} }
}.apply { }.apply {
if (playable && vectorPreferences.autoplayAnimatedImages()) { if (playableIfAutoplay && vectorPreferences.autoplayAnimatedImages()) {
mode(ImageContentRenderer.Mode.ANIMATED_THUMBNAIL) mode(ImageContentRenderer.Mode.ANIMATED_THUMBNAIL)
} }
} }

View File

@ -49,7 +49,7 @@ class DataAttachmentRoomProvider(
return getItem(position).let { return getItem(position).let {
when (it) { when (it) {
is ImageContentRenderer.Data -> { is ImageContentRenderer.Data -> {
if (it.mimeType == MimeTypes.Gif) { if (it.mimeType == MimeTypes.Gif || it.mimeType == MimeTypes.Webp) {
AttachmentInfo.AnimatedImage( AttachmentInfo.AnimatedImage(
uid = it.eventId, uid = it.eventId,
url = it.url ?: "", url = it.url ?: "",

View File

@ -135,7 +135,7 @@ class ImageContentRenderer @Inject constructor(
if (mode == Mode.ANIMATED_THUMBNAIL) it if (mode == Mode.ANIMATED_THUMBNAIL) it
else it.dontAnimate() else it.dontAnimate()
} }
.transform(cornerTransformation) .optionalTransform(cornerTransformation)
.into(imageView) .into(imageView)
} }
@ -167,7 +167,7 @@ class ImageContentRenderer @Inject constructor(
} }
req req
.fitCenter() .optionalFitCenter()
.into(target) .into(target)
} }
@ -211,7 +211,7 @@ class ImageContentRenderer @Inject constructor(
return false return false
} }
}) })
.fitCenter() .optionalFitCenter()
.into(imageView) .into(imageView)
} }

View File

@ -71,7 +71,7 @@ class RoomEventsAttachmentProvider(
allowNonMxcUrls = it.root.sendState.isSending() allowNonMxcUrls = it.root.sendState.isSending()
) )
if (content.mimeType == MimeTypes.Gif) { if (content.mimeType == MimeTypes.Gif || content.mimeType == MimeTypes.Webp) {
AttachmentInfo.AnimatedImage( AttachmentInfo.AnimatedImage(
uid = it.eventId, uid = it.eventId,
url = content.url ?: "", url = content.url ?: "",