电影播放完毕后退出全屏

时间:2012-03-17 16:57:23

标签: ios5 xcode4.2 mpmovieplayercontroller fullscreen

我正在尝试向我的电影播放器​​实施通知,这样一旦电影完成播放,它将退出全屏。到目前为止我的代码已发布在下面。 IBAction连接到一个按钮。另外在旁注中,我一直试图弄清楚如何在我的电影视图之上获得“播放符号”,这样用户只需按下它即可开始视频。有人知道如何实现吗?

- (void)viewDidLoad
{
    //Video player
    NSString *url = [[NSBundle mainBundle] pathForResource:self.navigationItem.title ofType:@"mov"];

    _player = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath: url]];
    _player.view.frame = CGRectMake(350, 200, 400, 400);
    [self.view addSubview:_player.view];
}

- (IBAction)playMovie
{
    [_player play];
}

1 个答案:

答案 0 :(得分:1)

您可以通过MPMoviePlayerPlaybackDidFinishNotification方法注册viewDidLoad通知来检测电影何时结束播放:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playerPlaybackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:_player];

然后在注册时指定的回调方法中执行您想要执行的任何操作:

- (void) playerPlaybackDidFinish:(NSNotification*)notification
{
    // movie finished playing
    _player.fullscreen = NO;
}