MPMoviePlayerController: How can I make my video loop?

前端 未结 3 2006
忘了有多久
忘了有多久 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];
            }
        }
    }
    
    0 讨论(0)
  • 2021-02-08 01:07

    For the timer you can create an Int variable that has the value of your slider and then use a performSelector afterDelay:

    int delayInt = 8; // Substitute the 8 for the value of your slider
    [self performSelector:@selector(myMethod) withObject:nil afterDelay:delayInt];
    

    And then in your "myMethod"

    -(void) myMethod{
    //the code to stop your player and remove view controller
    }
    
    0 讨论(0)
  • 2021-02-08 01:24

    Set the repeatMode property of your MPMoviePlayerController to MPMovieRepeatModeOne

    player = [[MPMoviePlayerViewController alloc]
              initWithContentURL:[NSURL fileURLWithPath:path]];
    player.moviePlayer.repeatMode = MPMovieRepeatModeOne;
    
    0 讨论(0)
提交回复
热议问题