0

我正在尝试观察播放结束通知,以便循环播放视频:

@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 通知?还有一种更简单的方法来循环视频吗?

4

0 回答 0