0

我想知道如何在我的应用程序加载时播放视频,然后使用MPMoviePlayerController. 我正在将视频加载到viewDidLoad. 视频播放完毕后如何跳转到下一页?

示例代码在这里:

  - (void)viewDidLoad
  {
      NSLog(@"Welcome to Home Page");
      [super viewDidLoad];
      self.parentViewController.view.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"bg-image-new.png"]];

      NSBundle * bundle =[NSBundle mainBundle];
      NSString * moviepath = [bundle pathForResource:@"opening_ani" ofType:@"mp4"];
      NSURL * movieurl = [[NSURL fileURLWithPath:moviepath]retain];
      MPMoviePlayerController * themovie = [[MPMoviePlayerController alloc]initWithContentURL:movieurl];
      themovie.view.frame=CGRectMake(0, 0, 1024, 768);
      [self.view addSubview:themovie.view];
      [themovie play];
      [themovie setShouldAutoplay:NO];
 }
4

1 回答 1

0

更新

我不是 100% 确定您可以在应用程序加载时播放视频。这里有一个很好的解释。


在上面的视图控制器中,在调用之前[themovie play],您可以注册一个播放完成的通知:

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(handleNotification:)
                                             name:MPMoviePlayerPlaybackDidFinishNotification
                                           object:nil];

在您的视图控制器中,您必须定义一个方法handleNotification:

    -(void)handleNotification:(NSNotification*)notification {
        if ( [notification.name isEqual:MPMoviePlayerPlaybackDidFinishNotification] ) {
            [[NSNotificationCenter defaultCenter] removeObserver:self
                                                            name:MPMoviePlayerPlaybackDidFinishNotification
                                                          object:nil];
            // move on to your next view here
        }
    }

更多关于 iOS 中的通知,它通常非常有用。此外,这里是有关的所有详细信息MPMoviePlayer,有一个部分列出了所有可能的通知及其详细信息。

于 2013-03-03T19:59:44.580 回答