MPMoviePlayerController 在第二个 X 自动暂停
MPMoviePlayerController automatic pause at second X
我必须在第二个 X 时自动停止播放器,我不知道我必须使用哪种通知。
之后,当用户点击屏幕上的任意位置时,播放器会继续 运行 视频。
- (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];
}
我试图捕捉电影帧并对其进行分析,看看是否该暂停视频了。
- (void) moviePlayBackPause:(NSNotification*)notification{
// check if it's time to pause the video
if([_moviePlayer currentPlaybackTime] == 6.0){
[_moviePlayer pause];
}
}
- 我必须使用哪种类型的通知来捕捉视频的当前时间?
提前感谢您的所有回复!
亲切的问候!
您可以使用 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];
}
我必须在第二个 X 时自动停止播放器,我不知道我必须使用哪种通知。 之后,当用户点击屏幕上的任意位置时,播放器会继续 运行 视频。
- (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];
}
我试图捕捉电影帧并对其进行分析,看看是否该暂停视频了。
- (void) moviePlayBackPause:(NSNotification*)notification{
// check if it's time to pause the video
if([_moviePlayer currentPlaybackTime] == 6.0){
[_moviePlayer pause];
}
}
- 我必须使用哪种类型的通知来捕捉视频的当前时间?
提前感谢您的所有回复! 亲切的问候!
您可以使用 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];
}