Video/audio streaming does not stop even if UIWebView is closed - iPad

I know this is pretty old thread, but for the sake of new developers like me.

My scenario was: I was using split controller, with media list on master and player in the detail controller section

I faced the same issue and tried all sorts of workaround.

I finally figured it out that the problem was simple, I was holding the reference of the detail controller in my master, and was not releasing the earlier detail controller. A simple release in the master at the right place solved the issue.


I have the same issue as stated but in this case the video that won't stop playing is a Youtube video embeded using the object/embed method.

I spent a long time trying to figure out how to get the video to stop playing and the only solution I found was to tell the UIWebView to load a blank page before dismissing the view:

    [self.webContent loadRequest:NSURLRequestFromString(@"about:blank")];

Edit(2015-05-12): As mentioned by @chibimai below, this answer by alloc_iNit works along the same lines but since my answer is from 5 years ago -- and his only 4 -- the linked answer may be more applicable. I no longer do iPhone dev work so I cannot determine which is better either way.


I also found this behaviour simply because the web view hadn't been released.


I'm working on the same problem. I've found that if you define something like this in your script tag:

function stopVideo(){ video.pause(); }
window.onunload = stopVideo;

Then in your UIViewController, add in:

-(void)viewWillDisappear:(BOOL)animated{
    [webView stringByEvaluatingJavaScriptFromString:@"window.onunload();"];
    [super viewWillDisappear:animated];
}

It seems to try to pause/stop the video for several seconds, but then you hear the audio continue to play!


Update!

This is a general bug with the media player. You have to set the playback time to -1 in order to make it really stop.