2012-08-08 219 views
0

我想知道如何在加载应用程序时播放视频,然后使用MPMoviePlayerController导航到ios应用程序中的下一页。我正在加载视频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]; 
} 

回答

0

UPDATE

我不是100%肯定,你可以播放视频,而应用程序加载。有一个很好的解释here

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

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


在你上面的视图控制器,呼吁[themovie play]之前,你可以为播放完成了注册通知

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

More about notifications in iOS,它在一般情况下非常有用。另外,here是关于MPMoviePlayer的所有详细信息,其中有一个部分列出了所有可能的通知及其详细信息。

相关问题