我正在尝试观察播放结束的通知,以便我可以循环播放视频:
@property (nonatomic, strong) MPMoviePlayerController *moviePlayer;
...
self.moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:theURL];
self.moviePlayer.controlStyle = MPMovieControlStyleNone;
[self.moviePlayer prepareToPlay];
self.moviePlayer.shouldAutoplay = YES;
[[NSNotificationCenter defaultCenter] addObserver: self selector:@selector(moviePlayBackDidFinish:) name: MPMoviePlayerPlaybackStateDidChangeNotification
object: self.moviePlayer];
- (void)moviePlayBackDidFinish:(NSNotification *)note {
if (note.object == self.moviePlayer) {
NSInteger reason = [[note.userInfo objectForKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey] integerValue];
if (reason == MPMovieFinishReasonPlaybackEnded) {
NSLog(@"THIS HAPPENS FOUR TIMES every time the movie ends");
[self.moviePlayer play];
}
}
}
如评论中所述,每次视频结束时,我都会收到此通知4次。玩家仍然循环,但我不喜欢我告诉它玩4次。
另外,如果我使用MPMoviePlayerPlaybackDidFinishNotification而不是MPMoviePlayerPlaybackStateDidChangeNotification,我只会收到一次通知。但是在这种情况下,电影不会循环播放。这都是因为以下内容根本不起作用:
self.moviePlayer.repeatMode = MPMovieRepeatModeOne;
所以我的问题是为什么每次电影结束时我都会收到4个MPMovieFinishReasonPlaybackEnded通知?还有一种更简单的循环视频方式吗?