BigImageViewer icon indicating copy to clipboard operation
BigImageViewer copied to clipboard

fix Fresco progress problem

Open 06peng opened this issue 8 years ago • 18 comments

首先感谢作者这么快添加了进度条显示。然后这个进度并不完美,似乎不是下载的进度,而是解码或者其他东西的进度,我试了好几张大图,一开始好久都不返回进度,后面瞬间就完成了。作者有兴趣的话可以确认一下这个问题,也许是我某些步骤弄错了-_-

06peng avatar Nov 17 '16 07:11 06peng

就是下载的进度,你可以在模拟器里面,把网络类型设置为 3g,就会发现变化了。当然,也不排除是图片加载库的问题,你用的 fresco 还是 glide?

Piasy avatar Nov 17 '16 13:11 Piasy

我测试的是fresco,用glide我以前也试过不准确,不过你glide用的方法我还没看,只是测试了fresco。用4g也试过了,毕竟我的图片可是有接近8M哦。你有时间可以试试看。http://ww3.sinaimg.cn/mw690/dd412be4gw1esr7nxekgag209f0h0b2f.gif

06peng avatar Nov 17 '16 13:11 06peng

我测试没问题呀,倒是 gif 图暂不支持

Piasy avatar Nov 17 '16 14:11 Piasy

哦?那我再多测试几次看看,谢谢了。

06peng avatar Nov 17 '16 14:11 06peng

多种网络确认了,还是不行。你看我打印出来的这个进度很明显是不正常的。26分58秒的时候开始load,27分10秒走到13%,隔了12秒,然后接下来的进度全在27分10秒,1秒之内全部走完。 11-18 10:26:58.288 10985-10985/com.github.piasy.biv.example D/BigImageView: showImage with thumbnail http://img1.imgtn.bdimg.com/it/u=1520386803,778399414&fm=21&gp=0.jpg, http://ww2.sinaimg.cn/large/dd412be4gw1esr6ijoebog208e0e1qv6.gif 11-18 10:26:58.315 10985-12903/com.github.piasy.biv.example D/NetworkSecurityConfig: No Network Security Config specified, using platform default 11-18 10:26:58.330 10985-10985/com.github.piasy.biv.example I/com.github.piasy.biv.indicator.progresspie.ProgressPieIndicator: 0 11-18 10:27:10.703 10985-10985/com.github.piasy.biv.example I/com.github.piasy.biv.indicator.progresspie.ProgressPieIndicator: 13 11-18 10:27:10.721 10985-10985/com.github.piasy.biv.example I/com.github.piasy.biv.indicator.progresspie.ProgressPieIndicator: 72 11-18 10:27:10.743 10985-10985/com.github.piasy.biv.example I/com.github.piasy.biv.indicator.progresspie.ProgressPieIndicator: 95 11-18 10:27:10.754 10985-10985/com.github.piasy.biv.example I/com.github.piasy.biv.indicator.progresspie.ProgressPieIndicator: 98 11-18 10:27:10.772 10985-10985/com.github.piasy.biv.example I/com.github.piasy.biv.indicator.progresspie.ProgressPieIndicator: 99 11-18 10:27:10.787 10985-10985/com.github.piasy.biv.example I/com.github.piasy.biv.indicator.progresspie.ProgressPieIndicator: 99 11-18 10:27:10.805 10985-10985/com.github.piasy.biv.example I/com.github.piasy.biv.indicator.progresspie.ProgressPieIndicator: 99 11-18 10:27:10.820 10985-10985/com.github.piasy.biv.example I/com.github.piasy.biv.indicator.progresspie.ProgressPieIndicator: 99 11-18 10:27:10.836 10985-10985/com.github.piasy.biv.example I/com.github.piasy.biv.indicator.progresspie.ProgressPieIndicator: 99 11-18 10:27:10.853 10985-10985/com.github.piasy.biv.example I/com.github.piasy.biv.indicator.progresspie.ProgressPieIndicator: 99 11-18 10:27:10.872 10985-10985/com.github.piasy.biv.example I/com.github.piasy.biv.indicator.progresspie.ProgressPieIndicator: 99 11-18 10:27:10.886 10985-10985/com.github.piasy.biv.example I/com.github.piasy.biv.indicator.progresspie.ProgressPieIndicator: 99 11-18 10:27:10.909 10985-10985/com.github.piasy.biv.example I/com.github.piasy.biv.indicator.progresspie.ProgressPieIndicator: 99 11-18 10:27:10.922 10985-10985/com.github.piasy.biv.example I/com.github.piasy.biv.indicator.progresspie.ProgressPieIndicator: 100 11-18 10:27:10.938 10985-10985/com.github.piasy.biv.example I/com.github.piasy.biv.indicator.progresspie.ProgressPieIndicator: 100 11-18 10:27:10.958 10985-10985/com.github.piasy.biv.example I/com.github.piasy.biv.indicator.progresspie.ProgressPieIndicator: 100 11-18 10:27:10.972 10985-10985/com.github.piasy.biv.example I/com.github.piasy.biv.indicator.progresspie.ProgressPieIndicator: 100 11-18 10:27:10.990 10985-10985/com.github.piasy.biv.example I/com.github.piasy.biv.indicator.progresspie.ProgressPieIndicator: 100 11-18 10:27:11.008 10985-10985/com.github.piasy.biv.example I/com.github.piasy.biv.indicator.progresspie.ProgressPieIndicator: 100 11-18 10:27:11.024 10985-10985/com.github.piasy.biv.example I/com.github.piasy.biv.indicator.progresspie.ProgressPieIndicator: 100 11-18 10:27:11.040 10985-10985/com.github.piasy.biv.example I/com.github.piasy.biv.indicator.progresspie.ProgressPieIndicator: 100 11-18 10:27:11.053 10985-10985/com.github.piasy.biv.example I/com.github.piasy.biv.indicator.progresspie.ProgressPieIndicator: 100 11-18 10:27:11.070 10985-10985/com.github.piasy.biv.example I/com.github.piasy.biv.indicator.progresspie.ProgressPieIndicator: 100

06peng avatar Nov 18 '16 02:11 06peng

对了,同时测试了glide 的下载进度是正常的,从1到100到可以正常打印,并且时间也正确。

06peng avatar Nov 18 '16 02:11 06peng

你是在 ProgressPieIndicator 里面加的 log 吧?你在 ImageDownloadSubscriber 里面加上 log 看看,后者是否也有问题。如果是,那就是 fresco 的实现问题。

glide 正常很好理解,它是在 http 响应读取数据的时候进行的统计。

Piasy avatar Nov 18 '16 02:11 Piasy

也有问题。估计是他们还是不愿意实现,我去年就提过isseus了,他们建议我showing a progress bar: http://frescolib.org/docs/progress-bars.html#_

06peng avatar Nov 18 '16 02:11 06peng

那就是 fresco 默认 progress update 有问题了。这倒也好办。

首先这里肯定不要用它们的 progress bar,因为显示图片压根没用 fresco。但是我们可以用 glide 的支持方式,毕竟 fresco 支持指定 http client,所以我们加个 intercepter,在读取 http 响应数据的时候进行统计,就可以了。

would you like to create a pr for this feature? :)

Piasy avatar Nov 18 '16 02:11 Piasy

haha,let me see see.

06peng avatar Nov 18 '16 03:11 06peng

哎,搞半天,OkHttp的进度也是不够完美。看这个类Progress 其实是得到responsebody后再切分返回进度。相当于多了一倍以上的时间,平时我读个gif要10秒,现在加这个进度要二十几秒。

06peng avatar Nov 18 '16 10:11 06peng

progress 是做一次转发,不会先全部读到,再切分返回。如果你真的遇到了时间更长,那应该是其他的问题。

Piasy avatar Nov 18 '16 11:11 Piasy

  • 总耗时理论上不会变,如果变了,肯定哪里出问题
  • Glide 没问题而 Fresco有问题,是因为FrescoImageloader里面在实际联网之前就回调了一次 callback.onProgress(0); // show 0 progress immediately,而Glide是在联网之后才回调,中间差了个联网时间(dns之类的耗时)

yiranshaxiao avatar Nov 22 '16 08:11 yiranshaxiao

两者的实现有点区别,Glide是每次加载图片的时候直接针对当前请求做进度的拦截。而Fresco是在初始化的时候ImagePipelineConfig中配置。不知道跟这个是否有影响。

06peng avatar Nov 23 '16 08:11 06peng

Fresco 进度监听确实有问题,尤其是下载国外图片时,进度条很快到达了 100,但图片根本没下载完。

Piasy avatar Jun 23 '17 14:06 Piasy

所以现在需要进度条的我都是用Glide。一个项目里面用了fresco和glide。【允悲】

06peng avatar Jun 28 '17 14:06 06peng

@06peng 能否花点时间研究如何解决?我的思路如下:

  1. 搞清楚 fresco 目前回调的逻辑,找出问题;
  2. 仿照 glide 的思路,使用自定义 OkHttpClient,自己计算进度;

Piasy avatar Jun 28 '17 14:06 Piasy

fresco无法针对每个图片拦截okhttp,只能针对底层的网络框架,但它下载完成后,还做了解码那一系列的操作也消耗了一定的时间。。。感觉无法破。。。在fresco官网提的issues都被close了。

06peng avatar Jun 30 '17 07:06 06peng