MPMoviePlayerController: How can I make my video loop?

前端 未结 3 2067
忘了有多久
忘了有多久 2021-02-08 00:55

Thank you in advance for any help, I am a newbie and would appreciate any help here.. I have this code to play a movie and it works great. Can somebody PLEASE tell me how to ma

3条回答
  •  生来不讨喜
    2021-02-08 01:01

    MPMovieRepeatModeOne is nice but it doesn't loop the video very smoothly. Try this below (copied from another post) :

    (I just got this working on my iPad 3 running iOS 5.1.1, base SDK iOS 5.1.)

    When setting up the movie player, set the repeat mode to MPMovieRepeatModeNone then add the notification

    [[NSNotificationCenter defaultCenter] addObserver:self
                selector:@selector(moviePlayerDidFinish:)
                name:MPMoviePlayerPlaybackDidFinishNotification
                                object:self.moviePlayer];
    

    Then set up your selector to filter when the movie finishes playing:

    - (void)moviePlayerDidFinish:(NSNotification *)note
    {
        if (note.object == self.moviePlayer) {
            NSInteger reason = [[note.userInfo objectForKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey] integerValue];
            if (reason == MPMovieFinishReasonPlaybackEnded)
            {
                [self.moviePlayer play];
            }
        }
    }
    

提交回复
热议问题