2012-04-25 65 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播放全屏电影

相关问题