2012-04-25 64 views
-1

,只要我打開我的應用程序具有播放視頻,通過視頻正在完成我必須添加一個UIButton上該視頻的時間後,是否有可能,我已經搜索,但我找不到鏈接,如果任何人已經通過這種情況,並解決它,你可以好好說我怎麼做? 添加視頻的代碼是:添加一個UIButton觀看視頻被播放完畢

- (void)viewDidLoad { 
    NSString *url = [[NSBundle mainBundle] pathForResource:@"splash_screen"ofType:@"mp4"];   
    MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:url]]; 
    player.view.frame = self.view.bounds; 
    [self.view addSubview:player.view]; 
    [player play]; 
    [super viewDidLoad]; 
} 
+0

[超級viewDidLoad中]總是首先調用超類的方法,這給了超類有機會做任何設置,你可能在以後在你的方法中依賴。 :) – rishi 2012-04-25 10:42:38

+0

@RIP:是的,這就是我想要的,所以我已經編寫了[super viewDidLoad]之上的代碼; – iYahoo 2012-04-25 11:04:20

回答

1

您可以使用 -

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

這將調用選擇「movieFinished」一旦電影完成之後,你可以做你想要的改變。

+0

謝謝你的回答,我嘗試了下面的代碼:MPMoviePlayerController * player = [aNotification object]; [[NSNotificationCenter defaultCenter] removeObserver:自 名:MPMoviePlayerPlaybackDidFinishNotification 對象:播放機]。 [player stop]; [self.view addSubview:newGameBtn]; 爲UIButton的代碼在init方法完成的,然後應用程序越來越crashed..saying: - [UIRoundedRectButton上海華]:消息發送到釋放實例0x6646120 – iYahoo 2012-04-25 10:50:31

+0

這似乎是問題在其他地方,你釋放newGameBtn地方? – rishi 2012-04-25 11:17:59

+0

不,我沒有發佈。 – iYahoo 2012-04-25 11:24:19

1

您可以使用MPMoviePlayerPlaybackDidFinishNotification通知。對於more Info

1

您可以添加觀察者來通知電影結束。

觀察者可以如下設置:

[[NSNotificationCenter defaultCenter] 
        addObserver: self 
         selector: @selector(myMovieFinishedCallback:) 
          name: MPMoviePlayerPlaybackDidFinishNotification 
         object: player]; 

欲瞭解更多信息,請參閱Apple doc清單2-1播放全屏電影

相關問題