Skip to content

GifDrawable.getCurrentPosition() may return the negative? #657

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
BCsl opened this issue May 13, 2019 · 6 comments
Closed

GifDrawable.getCurrentPosition() may return the negative? #657

BCsl opened this issue May 13, 2019 · 6 comments
Labels

Comments

@BCsl
Copy link

BCsl commented May 13, 2019

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.

@koral--
Copy link
Owner

koral-- commented May 13, 2019

Could you attach a code snippet which reproduces this issue?

@BCsl
Copy link
Author

BCsl commented May 15, 2019

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--

@BCsl
Copy link
Author

BCsl commented May 15, 2019

test_gif

@BCsl
Copy link
Author

BCsl commented May 16, 2019

Can you reproduce this problem? @koral--

@koral--
Copy link
Owner

koral-- commented May 21, 2019

Yep, I was able to reproduce this bug. I'll fix it ASAP.

@koral--
Copy link
Owner

koral-- commented Aug 1, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants