Skip to content
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

上传无法正常返回正确进度 #341

Open
ZQ-BB opened this issue May 16, 2022 · 0 comments
Open

上传无法正常返回正确进度 #341

ZQ-BB opened this issue May 16, 2022 · 0 comments

Comments

@ZQ-BB
Copy link

ZQ-BB commented May 16, 2022

当我使用 setProgressCallback 对put设置进度监听,但是没有正常返回进度
代码如下:

put.progressCallback = OSSProgressCallback { _, currentSize, totalSize ->
                receiverLengthLiveData.postValue(currentSize)
                progressLiveData.postValue((currentSize * 100F / totalSize).toInt())
            }

这边设置了livedata 进行监听

while (coroutineScope.isActive) {
            receiverLengthLiveData.value?.let {
                val speed = (it - prevLength) * 2 / 1024
                setProgress(
                    workDataOf(
                        SPEED to speed,
                        PROGRESS to progressLiveData.value
                    )
                )
                prevLength = it
                println("speed=$speed, progress=${progressLiveData.value} ")
            }
            delay(500)
        }

每0.5秒获取一次,完成后取消

但是实际显示
2022-05-16 16:39:02.307 30817-30862/com.zykj.download.test I/System.out: speed=0, progress=0
2022-05-16 16:39:02.831 30817-30862/com.zykj.download.test I/System.out: speed=1233, progress=100
2022-05-16 16:39:03.346 30817-30862/com.zykj.download.test I/System.out: speed=0, progress=100
2022-05-16 16:39:03.860 30817-30862/com.zykj.download.test I/System.out: speed=0, progress=100
2022-05-16 16:39:04.374 30817-30862/com.zykj.download.test I/System.out: speed=0, progress=100
2022-05-16 16:39:04.890 30817-30862/com.zykj.download.test I/System.out: speed=0, progress=100
2022-05-16 16:39:05.403 30817-30862/com.zykj.download.test I/System.out: speed=0, progress=100
2022-05-16 16:39:05.916 30817-30862/com.zykj.download.test I/System.out: speed=0, progress=100
2022-05-16 16:39:06.428 30817-30862/com.zykj.download.test I/System.out: speed=0, progress=100
2022-05-16 16:39:06.944 30817-30862/com.zykj.download.test I/System.out: speed=0, progress=100

在一开始虽然显示速度1233kb/s且已完成,但是并没有取消,通过抓包发现还是有上传连接,希望能修复这个问题

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

No branches or pull requests

1 participant