无尽的视频播放iOS



我想播放一个视频作为我的观点的背景,所以我决定使用MPMoviePlayerController来播放无尽的视频,我做了这样的东西:

NSString *pathForFile = [[NSBundle mainBundle] pathForResource:@"clear" ofType:@"mp4"];
player = [[MPMoviePlayerController alloc] init];
player.shouldAutoplay = YES;
player.repeatMode = MPMovieRepeatModeNone;
player.fullscreen = YES;
player.movieSourceType = MPMovieSourceTypeFile;
player.scalingMode = MPMovieScalingModeAspectFill;
player.contentURL =[NSURL fileURLWithPath:pathForFile];
player.controlStyle = MPMovieControlStyleNone;
[player.view setFrame:self.view.bounds];
[player.view setUserInteractionEnabled:NO];
[player.view setAlpha:0.0f];
[self.view addSubview:player.view];
[self.view sendSubviewToBack:player.view];
[player prepareToPlay];
[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(moviePlayerDidFinish:)
                                             name:MPMoviePlayerPlaybackDidFinishNotification
                                           object:player];
- (void)moviePlayerDidFinish:(NSNotification *)note {
if (note.object == player) {
    NSInteger reason = [[note.userInfo objectForKey:@"MPMoviePlayerPlaybackDidFinishReasonUserInfoKey"] integerValue];
    if (reason == MPMovieFinishReasonPlaybackEnded) {
        [player play];
    }
}

每次视频结束时都会调用我的方法,但播放器不再播放视频。我做错了什么?

提前谢谢。

- (void)moviePlayerDidFinish:(NSNotification *)note {
    if (note.object == player) {
        NSInteger reason = [[note.userInfo objectForKey:@"MPMoviePlayerPlaybackDidFinishReasonUserInfoKey"] integerValue];
        if (reason == MPMovieFinishReasonPlaybackEnded) {
             player.seekToTime[kCMTimeZero];
             // you must have to give time to start video again so use seekToTime
             [player play];
        }
    }
}

最新更新