0

アプリの読み込み中にビデオを再生し、.ios アプリで次のページに移動する方法を知りたいです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%確信していません。ここに素晴らしい説明があります。


上記のViewControllerで、を呼び出す前に[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 に答える