MPMoviePlayerController在第二个X自动暂停

时间:2015-07-11 07:46:34

标签: ios objective-c iphone mpmovieplayercontroller mpmovieplayer

我必须在第二个X自动停止播放器,我不知道我必须使用哪种通知。 之后,当用户点击屏幕上的任何位置时,播放器继续运行视频。

Observable<String> getImageUrl(int id) {
    return api.getImageUrl(id).map(SomeResponse::getImageUrl);
}

我试图捕捉电影画面并对其进行分析以确定是否有时间暂停视频。

- (IBAction)playMovie:(id)sender {
    NSString *filepath   =   [[NSBundle mainBundle] pathForResource:@"movie" ofType:@"m4v"];
    NSURL    *fileURL    =   [NSURL fileURLWithPath:filepath];
    _moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];

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

    //here I don't know which notification I have to used
    [[NSNotificationCenter defaultCenter] addObserver:self  selector:@selector(moviePlayBackPause:) name:MPMoviePlayerPlaybackStateDidChangeNotification object:_moviePlayer];

    _moviePlayer.controlStyle = MPMovieControlStyleDefault;
    _moviePlayer.initialPlaybackTime = 2.5;

    _moviePlayer.shouldAutoplay = YES;
    [self.view addSubview:_moviePlayer.view];
    [_moviePlayer setFullscreen:YES animated:NO];
    [_moviePlayer play];
}
  1. 我必须使用哪种类型的通知来捕捉视频的当前时间?
  2. 提前感谢您的所有回复! 亲切的问候!

1 个答案:

答案 0 :(得分:4)

您可以使用NSTimer停止播放视频。 应该有一个更好的方法来做到这一点,但有了计时器你也可以做到。

[_moviePlayer play];
[NSTimer scheduledTimerWithTimeInterval:6 //Time in seconds
                                 target:self
                               selector:@selector(moviePlayBackPause) //Method called when the timer is completed.
                               userInfo:nil
                                repeats:NO];
    }
}

- (void) moviePlayBackPause {
  [_moviePlayer pause];
}