我想播放视频作为我视图的背景,所以我决定使用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];
}
}
每次视频结束时都会调用我的方法,但播放器不会再播放视频。我做错了什么?
提前致谢。
答案 0 :(得分:0)
- (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];
}
}
}