28 Jun 2010

This morning, Elliot tweeted a link to some instruments for Ableton. I was using Twitter for iPhone so I tapped on the link to open it up in the internal web browser and then proceeded to play the embedded audio in the web page. Half way through, I tapped the back button to get back to my tweets and noticed that the audio kept playing.

The issue is that the UIWebView keeps playing embedded media unless you reset it. But reset how?

I just tested it out and the only way I could get the audio to stop was to load an empty string into the UIWebView like this:

[self.webBrowser loadHTMLString:@"" baseURL:nil];

Things that didn't work include calling the UIWebView's stopLoading method, setting the web view as hidden, removing it from its superview or setting it to nil and/or releasing it.

I've seen this issue with other apps that have embedded UIWebView components so remember folks, reset that web view by loading in an empty string before hiding it to make sure any playing media is stopped.

Add Your Comment

Spam Protection by WP-SpamFree

How to stop media playback on a UIWebView

A number of apps, including Twitter for iPhone, don't stop media playback in embedded browsers when hiding them. Here's how to fix that.

  1. Thank you very much! Gorgeous Method! You are guru!
    I spended 3 hours to stop youtube movie of UIWebView for iPad gallery app. “StopLoading”, “Releasing” didn’t stop playing video.

    Thank you!

    Jong Ho Park