【问题标题】:Exit fullscreen when movie is done playing电影播放完毕后退出全屏
【发布时间】:2012-03-17 16:57:23
【问题描述】:

我正在尝试在我的电影播放器​​中实现通知,以便电影播放完毕后,它将退出全屏。到目前为止,我在下面发布了代码。 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];
}

【问题讨论】:

    标签: ios5 xcode4.2 mpmovieplayercontroller fullscreen


    【解决方案1】:

    您可以通过在viewDidLoad 方法中注册MPMoviePlayerPlaybackDidFinishNotification 通知来检测电影何时播放完毕:

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

    然后在注册时指定的回调方法中执行任何你想做的动作:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-27
      • 1970-01-01
      • 2023-03-13
      • 1970-01-01
      相关资源
      最近更新 更多