I am setting up an UIWebView
to show the contents of a web camera through a URL that retrieves an MPJEG-stream.
I found out that if I wanted to switch to a different camera, it looked smoother if I did not reset the entire contents of the UIWebView
, but instead set up a javascript function in the page I loaded into it, to replace the contents of the image, like this:
<img id='iImage' src='about:blank'>
<script type='text/javascript'>
function show(url)
{
iImage.src = url;
}
</script>
If I did not do this, every time I switched to a new url, the UIWebView
went white for a second or two until the new content was ready to be displayed, with the above code it just replaces the contents directly, no whiteout.
However, if I switch back and forth between two videostreams, at some point I get an error in the UIWebView
, and by trial and error I've found out that this happens the 4th time I show the same videostream in the view. If I try to open up 4 videostreams in browser-tabs, the 4th get stuck in a loading cycle, until I close one of the previous three.
This leads me to believe that:
src
attribute on the <img...>
tag does not close the previous streamCan this be linked to keepalive? Could the webkit browser system keep the previous streams alive, even though I have stopped showing them in the <img...>
tag?
Basically, to reproduce I can do this:
UIWebView
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?
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With