views:

728

answers:

2

So I can't find any documentation on how to do this, maybe someone knows what's going on here.

I'm in a UITableView (with a UINavigationController) in my application, and launching a UIWebView that loads an mp3 file on the internet by pushing the Web View's controller onto the navigation controller's stack. This works great, the file launches and plays in the quicktime player that Safari uses.

The problem is that once the audio file is finished playing, or the user clicks the done button, the player is released and the app goes back to an empty webView with my navigation bar. I can hit the back button to get back to my original UITableView, but that blank screen is ugly and needs to go.

So, what action can i use to put a [webviewcontroller.navigationcontroller popviewcontroller] message in? Is it loading an instance of some other class (like AVAudioPlayer) to play the audio? Do i need to subclass something? Apple's documentation on how it plays audio in UIWebView is basically nonexistant.

+1  A: 

You can fake it by having some javascript change location.href, and then doing something like this:

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request
  navigationType:(UIWebViewNavigationType)navigationType {

 NSString* path=[[request URL] relativePath];
 BOOL shouldContinue=YES;

 if ([path isEqualToString:@"/_my_custom_link"])
 {
  shouldContinue=NO;
  // do magical stuff
 }
 return shouldContinue;
}

If that doesn't work, you can always poll it by doing a

stringByEvaluatingJavaScriptFromString
slf
whoa, I'm not sure if that's what I was asking for. When the mp3 finishes playing, it seems to trigger the same event as clicking the "is done" button, both of which take the user to a blank webview. What I want to do is pop the view controller off the stack when they are about to hit this page.
Yeah, it's a bit of a hack but basically through javascript you should be able to fire something on a timer or event that changes the location, then listen for that "event" in the delegate and pop
slf
+4  A: 

Ok, so I found a much better, much simpler solution; one that i had to delete lines of code from my app to use. I just used UIWebview initWithFrame:CGRectMake(0.0,0.0,1.0,1.0), didn't add it to the view, then called an NSURLRequest, and hooked it up to my button. The media player fullscreens automagically, and there's no need to call the nav controller.

nice hack, glad to hear you fixed it
slf