/**
* Start Loading Request
* This is where most of the magic happens... We take the request(s) and process the response.
* From here we can re direct links and other protocalls to different internal methods.
*/
- (BOOL)webView:(UIWebView *)theWebView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
/*** Credit goes to PanMan (Martijn Pannevis <
mar...@panman.nl>) for this elegent hack
Watch for video URLs and launch them in the media player. No HTML5 video tag necessary, just a normal link.
***/
NSURL *url = [request URL];
if (![[url scheme] isEqualToString:@"gap"] && ([[[url path] pathExtension] isEqualToString:@"mp4" ] || [[[url path] pathExtension] isEqualToString:@"m4v" ] || [[[url path] pathExtension] isEqualToString:@"m3u8" ] || [[[url path] pathExtension] isEqualToString:@"mp3" ])) {
//video files are .mp4 or m4v, stream indexes are m3u8
//it's a movie, go play!
//NSLog([url]);
[self playMovieAtURL:url];
return NO;
} else {
return [ super webView:theWebView shouldStartLoadWithRequest:request navigationType:navigationType ];
}
}
-(void)playMovieAtURL:(NSURL*)theURL {
MPMoviePlayerController* theMovie=[[MPMoviePlayerController alloc] initWithContentURL:theURL];
theMovie.scalingMode=MPMovieScalingModeAspectFit;
// Register for the playback finished notification.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(myMovieFinishedCallback:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:theMovie];
// Movie playback is asynchronous, so this method returns immediately.
[theMovie play];
}
-(void)myMovieFinishedCallback:(NSNotification*)aNotification
{
MPMoviePlayerController* theMovie=[aNotification object];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:theMovie];
[theMovie stop];
// Release the movie instance created in playMovieAtURL
//Bug fix for autoplay bug on 3.0
float version = [[[UIDevice currentDevice] systemVersion] floatValue];
if (version >= 3.0) {
// iPhone 3.0 code here
// theMovie.initialPlaybackTime = -1.0; //Breaks on 2.x compiling
[theMovie setInitialPlaybackTime: -1.0]; //Only gives a warning on 2.x :)
}
[theMovie release];
NSLog(@"Go STOP received");