MPMoviePlayerController: How can I make my video loop?

↘锁芯ラ 提交于 2019-12-03 05:55:25
Jacob Relkin

Set the repeatMode property of your MPMoviePlayerController to MPMovieRepeatModeOne

player = [[MPMoviePlayerViewController alloc]
          initWithContentURL:[NSURL fileURLWithPath:path]];
player.moviePlayer.repeatMode = MPMovieRepeatModeOne;
Jeeri

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

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
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!