android-gif-drawable
android-gif-drawable copied to clipboard
GifDrawable.getCurrentPosition() may return the negative?
I call GifDrawable.getCurrentPosition() every 10ms to update the UI progress. This method will return a negative value when the gif is closing to the end.
Could you attach a code snippet which reproduces this issue?
class TestActivity : AppCompatActivity() {
var mGif: GifDrawable? = null
@SuppressLint("CheckResult")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_test)
mGif = GifDrawable(resources, R.raw.test_gif)
Observable.interval(10, TimeUnit.MILLISECONDS)
.compose(RxLifecycleCompact.bind(this).withObservable())
.observeOn(AndroidSchedulers.mainThread())
.subscribe { tick ->
mGif?.also {
if (it.currentPosition < 0) {
if (BuildConfig.LOG_ENABLE) {
Log.e("GIF", "current position: ${it.currentPosition}")
}
}
pb_gif?.progress = ((it.currentPosition / it.duration.toFloat()) * 100).toInt()
}
}
iv_gif_test.setImageDrawable(mGif)
}
override fun onResume() {
super.onResume()
mGif?.start()
}
override fun onPause() {
super.onPause()
mGif?.pause()
}
}
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:background="@android:color/white"
android:layout_height="match_parent">
<ImageView android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:id="@+id/iv_gif_test"/>
<ProgressBar android:layout_width="match_parent"
android:layout_height="3dp"
style="@style/Base.Widget.AppCompat.ProgressBar.Horizontal"
android:id="@+id/pb_gif"
android:indeterminate="false"
android:layout_gravity="bottom"
android:max="100"
tools:progress="50"
/>
</FrameLayout>
@koral--
Can you reproduce this problem? @koral--
Yep, I was able to reproduce this bug. I'll fix it ASAP.
Sorry for the very long delay. The fix will be released in v 1.2.25.
The current position was miscalculated when the animation was on the last frame (in terms of what is displayed) on the subsequent animation loops.
The formula should be <whole loop duration> - <remainder duration of the last frame displayed so far>
but there was 0
used instead of the loop duration.