Search code examples
ipadvideoiframeios4uiwebview

Programmatically stopping a video playing in an UIWebView's iframe


I have a series of youtube and vimeo videos playing in an iFrame in an UIWebview.

Everything is great here -- the videos' load and play just fine. Each video is stored in its own webview which can be paged through. The user swipes back and forth to view videos in the playlist.

This creates the problem of stopping the video however. The video is "offscreen" but the video is still playing. Is there anyway I can stop the video? It can be any method, tied to a touch, a swipe, a javascript command sent to the webview.

I'm open to suggestions here; I'm just drawing a blank.


Solution

  • An option could be detecting when the UIWebView is off screen and refreshing the page. Since the user may never bring that view back on screen, however, a more data friendly option could be, when the UIWebView is off screen, load a blank page. Then, if the user scrolls the view back on screen, reload. I'm not sure if there is any other simple way other than removing the view from its superview, destroying it, hiding it, etc.

    Of course, Javascript is an option too. Doc is available at http://code.google.com/apis/youtube/iframe_api_reference.html.