完成播放视频后如何移动到另一个ViewController?

时间:2014-08-18 15:49:32

标签: ios objective-c

完成播放视频后如何移动到另一个ViewController?从'2'到'1'(查看截图) http://i.stack.imgur.com/FVFlh.png

viewDidLoadvideoViewControler)中的代码:

NSURL *url = [NSURL URLWithString:@"_http://scontent-a.cdninstagram.com/hphotos-xfa1/t50.2886-16/10619021_616434485141882_380154097_n.mp4"];

videoPlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:url];

[videoPlayer.moviePlayer prepareToPlay];
[videoPlayer.moviePlayer play];
[self presentMoviePlayerViewControllerAnimated:videoPlayer];    

NSArray *viewControllers = [[self navigationController] viewControllers];
[self.navigationController popToViewController:viewControllers[1] animated:NO];

2 个答案:

答案 0 :(得分:0)

为MPMoviePlayerPlaybackDidFinishNotification添加一个观察者,它将在电影结束时通知您,然后您可以回弹视图控制器。

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

答案 1 :(得分:0)

您必须注册完成结束通知,例如在viewDidLoad:

// Register for finished notification
[[NSNotificationCenter defaultCenter] addObserver:self 
    selector:@selector(moveToView2:)
    name:MPMoviePlayerPlaybackDidFinishNotification
    object:self.moviePlayerViewController.moviePlayer];

添加通知方法并调用segue转到另一个视图:

- (void) moveToView2:(NSNotification *) notification {
    [self performSegueWithIdentifier:@"IDENTIFIER" sender:self];
}

只需确保将IDENTIFIER替换为视图A和B之间的segue标识符。