如何确定最后一次 PictureListener.onNewPicture() 调用?

发布于 2024-11-03 17:30:06 字数 709 浏览 2 评论 0原文

一方面,WebViewClient.onPageFinished() 是判断网页何时完成加载(如 HttpGet 中)的好方法,但它不会告诉我网页何时完成渲染。

另一方面,只要页面被(重新)渲染,PictureListener.onNewPicture() 就会通知我。

这对于大多数情况来说都很好,但对于大量 Javascript 渲染的页面(例如 YouTube),我需要能够知道(针对该页面)最后 此类渲染发生的时间。

类似PictureListener.onNewPictureFinished()

当然,这样的功能在 PictureListener 中不存在,所以我现在想知道是否有可能提出类似的功能或解决方法?

有什么想法如何确定最后 PictureListener.onNewPicture() 调用吗?

(我的一个想法是设置一个计时器,该计时器将决定“如果在 X 秒内没有调用 onNewPicture(),则前一个一定是最后一个”。这是一种极其不准确且模糊的方法,在许多情况下肯定会失败)。

On one hand, WebViewClient.onPageFinished() is a great way to tell when a web page finished loading (as in HttpGet) but it will not tell me when the web page has finished rendering.

On the other hand, there is PictureListener.onNewPicture() which notifies me whenever the page has been (re)rendered.

This is great for most cases, but for pages which are heavily Javascript-rendered (like YouTube, for example), I need to be able to know when the last such render (for that page) occurred.

Something like PictureListener.onNewPictureFinished().

Such function doesn't exist, of course, in PictureListener, so I am now wondering whether it is possible to come up with similar functionality or workaround?

Any ideas how to determine last PictureListener.onNewPicture() call?

(one idea that I have is to set a timer that will decide that "if within X seconds no onNewPicture() has been called, then the previous one must have been the last". This is an extremely inaccurate & fuzzy approach, which is guaranteed to fail in many scenarios).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

幸福还没到 2024-11-10 17:30:06

我在稍微不同的情况下遇到了相同的问题

API 不提供最后一张 onNewPicture 的回调,因为
WebView 本身不知道当前图片是否是最后一张。

您的一些优化解决方法已经足够好了......

如果您有机会更改 html,您可以通过 JavaScript接口
例如,当视频结束时会调用它。

I had the same question in a bit different situation.

API doesn't provide callback for the last onNewPicture, because
WebView itself doesn't know current picture is last or not.

Your workaround with some optimization is enough good...

If you have a chance to change html, you can include js-callback through JavaScript Interface.
For example, it will be called when video will finish.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文