1

我有一个 html 按钮UIWebView,点击它会推送一个UIViewController带有编程的 segue 动作的按钮。如何在加载 UIViewController 时播放电影MPMoviePlayer。此代码播放 Movie inMPMoviePlayerViewController而不是 segue push UIViewController。我想在 segue 推送的 UIViewController 中播放电影。

- (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;
}
4

1 回答 1

1

使用MPMoviePlayerController。您可以将其添加为self.view.

例如:

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];

有关更多详细信息,请查看上面的苹果文档链接。

更新:

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
于 2012-12-10T23:32:09.043 回答