Reputation: 91
I have a html button in UIWebView
, which on click pushes a UIViewController
with programmed segue action. How to play a movie upon loading of the UIViewController with MPMoviePlayer
. This code plays the Movie in MPMoviePlayerViewController
instead of the segue pushed UIViewController
. I want to play the movie in the UIViewController pushed by segue.
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
if ([request.URL.scheme isEqualToString:@"inapp"]) {
if ([request.URL.host isEqualToString:@"capture"]) {
[self performSegueWithIdentifier: @"SegueAction" sender: self];
NSURL * urlA1 = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"A1"ofType:@"mp4"]];
MPMoviePlayerViewController *playercontrollerA1 = [[MPMoviePlayerViewController alloc] initWithContentURL:urlA1];
playercontrollerA1.moviePlayer.repeatMode = MPMovieRepeatModeOne;
[self presentMoviePlayerViewControllerAnimated:playercontrollerA1];
playercontrollerA1.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
// do capture action
}
return NO;
}
return YES;
}
Upvotes: 1
Views: 1585
Reputation: 23278
Use MPMoviePlayerController . You can add that as a subview of self.view.
For eg:
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL: myURL];
[player prepareToPlay];
[player.view setFrame: myView.bounds]; // player's frame must match parent's
[self.view addSubview: player.view];
// ...
[player play];
Fore more details please check the apple doc link above.
Update:
NSURL *urlA1 = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"A1"ofType:@"mp4"]];
MPMoviePlayerController *moviePlayer =
[[MPMoviePlayerController alloc] initWithContentURL:urlA1];
moviePlayer.repeatMode = MPMovieRepeatModeOne;
[self.view addSubview:moviePlayer.view];
moviePlayer.movieSourceType = MPMovieSourceTypeFile;
// do capture action
Upvotes: 1