Tencent / libpag

The official rendering library for PAG (Portable Animated Graphics) files that renders After Effects animations natively across multiple platforms.
https://pag.art
Other
4.79k stars 439 forks source link

关于pagVIew使用进度回调问题 #2072

Open HarryPotterr opened 5 months ago

HarryPotterr commented 5 months ago

【版本信息】

4.2.100

【平台信息】

Android 原生

【预期的表现】

                pagView.apply {
                    composition = PAGFile.Load(assets, "pag/pag_birthday_cake.pag")//文件大概有900kb
                    setScaleMode(PAGScaleMode.Zoom)
                    addListener(object : PAGView.PAGViewListener {
                        override fun onAnimationStart(view: PAGView?) {
                            LogHelper.e("onAnimationStart")
                        }

                        override fun onAnimationEnd(view: PAGView?) {
                            LogHelper.e("onAnimationEnd state->$isStop")
                            if (isStopCake) {//结束动画
                               //自己的逻辑
                            }
                        }

                        override fun onAnimationCancel(view: PAGView?) {
                            LogHelper.e("onAnimationCancel")
                        }

                        override fun onAnimationRepeat(view: PAGView?) {
                            LogHelper.e("onAnimationRepeat")
                        }

                        override fun onAnimationUpdate(p0: PAGView) {
                            LogHelper.e("onAnimationUpdate")
                            if (!isStop) {
                                val process = p0.progress
                                LogHelper.e("onAnimationUpdate->$process")
                                if (process >= 0.8) {
                                    p0.progress = 0.0
                                    play()
                                }
                            }
                        }
                    })
                     play()//播放
                }

我的需求是控制动画在特定情况下(isStop为false)只播放前面80%的帧率,通过判断pagview.progress。等到isStop为true就停止获取进度,然后播放完成最后一次。大多数情况下正常,在重复打开关闭页面播放动画会偶尔出现获取progress异常,日志如下:

【实际的情况】

-》onAnimationStart -》onAnimationUpdate -》onAnimationUpdate process->1.0 -》onAnimationUpdate -》onAnimationUpdate process->3 333333333333334E-4 -》onAnimationUpdate -》onAnimationUpdate process->3.333333333333334E-4onAnimationUpdate -》onAnimationUpdate -》onAnimationUpdate process->1.0 -》onAnimationEnd: state->false -》onAnimationUpdate -》onAnimationupdate process->3.333333333333334E-4 -》onAnimationUpdate -》onAnimationupdate process->3.333333333333334E-4 文件大小大约900kb,日志中会在第一次play()就出现进度为1的情况。希望能帮忙解决一下,期待您的答复。

【Demo及附件】