MPMoviePlayerViewController repeatMode not working?
I have a problem with MPMoviePlayerViewController and it's property repeatMode. It's stated that setting it to a MPMovieRepeatModeOne value will cause player to r开发者_如何学Goepeat playback. I use following code to play video in a loop but it just stops after the end.
MPMoviePlayerViewController *mpViewController =[[MPMoviePlayerViewController alloc] init];
mpViewController.moviePlayer.contentURL= movieURL;
self.aPlayer=mpViewController;
self.aPlayer.moviePlayer.repeatMode=MPMovieRepeatModeOne;
mpViewController.repeatMode=MPMovieRepeatModeOne;
worked for me but I did not have the url line or the self.'s
My next line after the above was [mpViewController play];
Remove this line
[self.aPlayer.moviePlayer setRepeatMode:MPMovieRepeatModeOne];
and put:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayerDidChangeState:)
name:MPMoviePlayerPlaybackStateDidChangeNotification
object:self.player];
and implement
- (void)moviePlayerDidChangeState:(NSNotification *)note
{
MPMoviePlaybackState playbackState = [self.player playbackState];
if(playbackState==MPMoviePlaybackStateStopped ||playbackState==MPMoviePlaybackStatePaused || playbackState==MPMoviePlaybackStateInterrupted)
{
if (note.object == self.player) {
NSInteger reason = [[note.userInfo objectForKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey] integerValue];
if (reason == MPMovieFinishReasonPlaybackEnded)
{
[self.player play];
}
}
}
}
精彩评论