views:

1092

answers:

1

I'd like a link in a UIWebView that plays a local .mp4 file. I know how to load the MPMoviePlayerControler but am not sure how to set it up in the UIWebView. I have a UIView with a UIWebView inside of it. How do I use the MPMoviePlayerControler with this setup?

+1  A: 

If I understand your question properly, you are not asking how to load an .mp4 into the player, you're asking how to put a link into the HTML that gets rendered in the web view such that when that link is clicked your code to create the movie player gets run. There is no "local file" syntax that's supported, so what you need to do is make your controller a delegate for the web view's messages (by implementing <UIWebViewDelegate> and setting the delegate of the web view) and define a handler for

webView:shouldStartLoadWithRequest:navigationType:

This handler is run every time an URL is about to be loaded by the web view. Your implementation should simply return YES for all requests except for one special type.

You then pick an arbitrary custom URL scheme, such as mp4movie://path/to/the/file and use that URL in the anchor in your HTML page. In the handler above, look for requests that match this scheme, parse out the path/to/the/file, launch the MPMoviePlayerController, and return NO.

ddoughty