2012-08-08 272 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的所有詳細信息,其中有一個部分列出了所有可能的通知及其詳細信息。

相關問題