获取 GIF 文件的持续时间/长度(以毫秒为单位)

问题描述 投票:0回答:1

我知道 SO 上有很多类似的问题,但大多数都使用 MOVIE 类,该类已被弃用。现在 Android 建议对 GIF 使用 AnimatedImageDrawable 类,但它没有提供任何机制来获取 GIF 的持续时间/长度。

如果有任何机制可用于相同的情况,请告诉我。

android kotlin gif android-glide
1个回答
0
投票

对我有用的解决方案是使用 github/koral--/android-gif-drawable

对于放置在

error.gif
中的我的文件
res/drawable
,以下内容提供了正确的预期长度。

implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.25'

import pl.droidsonroids.gif.GifDrawable

val gifDrawable = GifDrawable(resources, R.drawable.error)
val duration = gifDrawable.duration
© www.soinside.com 2019 - 2024. All rights reserved.