10

我正在设置一个UIWebView通过检索 MPJEG 流的 URL 来显示网络摄像头的内容。

我发现如果我想切换到不同的相机,如果我不重置整个内容,它看起来会更流畅UIWebView,而是在我加载的页面中设置一个javascript函数,以替换图像的内容, 像这样:

<img id='iImage' src='about:blank'>
<script type='text/javascript'>
function show(url)
{
    iImage.src = url;
}
</script>

如果我不这样做,每次我切换到一个新的 url 时,都会UIWebView变白一两秒钟,直到准备好显示新的内容,上面的代码只是直接替换内容,没有白屏。

但是,如果我在两个视频流之间来回切换,有时会出现错误UIWebView,并且通过反复试验,我发现这是第四次在视图中显示相同的视频流时发生这种情况。如果我尝试在浏览器选项卡中打开 4 个视频流,则第 4 个会卡在加载周期中,直到我关闭前三个中的一个。

这让我相信:

  1. 有问题的相机只能同时服务 3 个流
  2. 更改标签src上的属性<img...>不会关闭上一个流

这可以链接到keepalive吗?即使我已经停止在<img...>标签中显示它们,webkit 浏览器系统能否保持以前的流处于活动状态?

基本上,要重现我可以这样做:

  1. 将以上内容设置在一个UIWebView
  2. 调用 4 次:wv.EvaluateJavascript("show(url)")

On the 4th call, I get a blue question mark in the middle.

Can keep-alive be the culprit? And if so, can I control it?

4

1 回答 1

5

This is being caused by WebKit not stopping loading of an image resource even if the source is changed. This normally doesn't cause a problem for images but a never-ending streaming image will cause it to never let go until the page is reloaded.

There is a bug filed against Chromium that points at this issue. https://code.google.com/p/chromium/issues/detail?id=73395

From the comment thread, a workaround is to call window.stop() before changing the image. This is the same as clicking stop in the browser and causes all loading resources to abort. Hopefully, the fact that this isn't causing the page to reload will avoid your white flash.

I'd give the following a try:

<img id='iImage' src='about:blank'>
<script type='text/javascript'>
function show(url)
{
    window.stop();
    iImage.src = url;
}
</script>
于 2012-05-13T23:49:39.893 回答