About Me

My photo
Drum & Bass Producer, Software Developer, Love my Cats

iOS snippet : How to stop all audio html elements played inside a UIWebView when I close it?


I wrote an app with a UIWebView that has audio html5 tags in it. While the audio element is played, closing the webview doesn't stop the audio playback.

So, how do we stop it?

When the webview is supposed to exit, run this code:


NSURLRequest *emptyRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:@"about:blank"]];
    [webView loadRequest:emptyRequest];


This code actually loads an empty request, thus killing all the current elements and objects in the current webview.

I hope this little snippet helps you when your html5 audio keeps playing even after you closed the webview.