MPMoviePlayerController:如何让我的视频循环?

时间:2011-01-02 21:51:41

标签: cocoa-touch mpmovieplayercontroller

提前感谢您的帮助,我是新手,非常感谢这里的任何帮助.. 我有这个代码来播放电影,效果很好。有人可以告诉我如何使这个电影循环和重播从一开始不停止(任何代码都会有帮助)。另外,我想知道如何一个接一个地播放2部电影,最好是淡入淡出或平滑过渡。感谢您的帮助

#import "MyAppViewController.h"

@implementation MyAppViewController

-(IBAction)button:(id)sender{
 NSString *path = [[NSBundle mainBundle]
       pathForResource:@"mymovie" ofType:@"mp4"];

 player = [[MPMoviePlayerViewController alloc]
     initWithContentURL:[NSURL fileURLWithPath:path]];

 [self presentMoviePlayerViewControllerAnimated:player];

}

3 个答案:

答案 0 :(得分:23)

MPMoviePlayerController的{​​{3}}属性设置为MPMovieRepeatModeOne

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

答案 1 :(得分:20)

MPMovieRepeatModeOne很不错,但它不会非常顺利地循环播放视频。请尝试以下方法(从其他帖子复制):

(我刚刚在我的iPad 3上运行iOS 5.1.1,基础SDK iOS 5.1。)

设置电影播放器​​时,将重复模式设置为MPMovieRepeatModeNone,然后添加通知

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

然后设置选择器以在电影结束播放时进行过滤:

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

答案 2 :(得分:1)

对于计时器,您可以创建一个具有滑块值的Int变量,然后使用performSelector afterDelay:

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

然后在你的“myMethod”中

-(void) myMethod{
//the code to stop your player and remove view controller
}