MPMoviePlayerViewController repeatMode无法正常工作?

时间:2010-07-22 09:07:17

标签: iphone mpmovieplayercontroller

我遇到了MPMoviePlayerViewController的问题,它的属性是repeatMode。据说将其设置为MPMovieRepeatModeOne值将导致播放器重复播放。我使用以下代码在循环中播放视频,但它只是在结束后停止。

MPMoviePlayerViewController *mpViewController =[[MPMoviePlayerViewController alloc] init];
mpViewController.moviePlayer.contentURL= movieURL;
self.aPlayer=mpViewController;
self.aPlayer.moviePlayer.repeatMode=MPMovieRepeatModeOne;

2 个答案:

答案 0 :(得分:1)

mpViewController.repeatMode=MPMovieRepeatModeOne;

为我工作,但我没有网址或自我。

我在上面的下一行是[mpViewController play];

答案 1 :(得分:1)

删除此行

[self.aPlayer.movi​​ePlayer setRepeatMode:MPMovieRepeatModeOne];

并提出:

   [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(moviePlayerDidChangeState:)
                                                 name:MPMoviePlayerPlaybackStateDidChangeNotification
                                               object:self.player];

并实施

- (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];
            }
        }
    }
}