2012-05-07 27 views
0

似乎我有重复模式的问题:它不重复视频。MPMoviePlayerController重复模式不工作在viewDidLoad

这是视频我在执行代码:

- (void)viewDidLoad{ 

    NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"Space Particle" ofType:@"mp4"]]; 


    MPMoviePlayerViewController *playerController = [[MPMoviePlayerViewController alloc]initWithContentURL:url]; 
    [self presentMoviePlayerViewControllerAnimated:playerController]; 
    [playerController.moviePlayer prepareToPlay]; 
    playerController.moviePlayer.movieSourceType = MPMovieSourceTypeFile; 
    playerController.moviePlayer.controlStyle = MPMovieControlStyleNone; 
    playerController.moviePlayer.scalingMode = MPMovieScalingModeAspectFill; 
    playerController.moviePlayer.repeatMode = MPMovieRepeatModeOne; 
    [MyView1 addSubview: playerController.view]; 


    [playerController.moviePlayer play]; 
    [playerController release];playerController=nil; 
} 

它可以作为动画背景,与它上面的按钮。视频播放时,但完成后,它不会重复。

我发现,作为一个IbAction,它重复,但作为一个viewDidLoad它不会。

请注意,“MyView”插座已链接到自定义UIButton,并且它位于电影播放的按钮视图中。

我使用的视频尺寸不是很大。

我的目标是,电影必须重复使用viewdidload方法,以便自动播放和重复。

请问,有什么我做错了?如何解决它的建议?任何帮助,将不胜感激。

+0

为解决方案,你可以看看我的答案这种类型的相同的问题[这里](http://stackoverflow.com/a/18710826/2695503) –

回答

0

同样的问题。我用接下来的步骤解决了它: 1)订阅端播放通知

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

2)重放手动启动在moviePlayBackDidFinished方法

+0

我真的很感激你的帮助非常非常。 – miqueas1234567

+0

但我需要视频循环(完成后自动重复) – miqueas1234567

+0

另外我不知道如何使用代码 – miqueas1234567

6

尝试下面的代码。这是完美的。

NSURL *fileUrl = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"Video" ofType:@"mp4"]]; 
    MPMoviePlayerViewController *moviePlayerController = [[MPMoviePlayerViewController alloc]initWithContentURL:fileUrl]; 
    [moviePlayerController.moviePlayer prepareToPlay]; 
    [moviePlayerController.moviePlayer setRepeatMode:MPMovieRepeatModeOne]; 
    [moviePlayerController.moviePlayer setControlStyle:MPMovieControlStyleEmbedded]; 
    [self.view addSubview:moviePlayerController.view]; 
2

它在viewDidLoad函数完成后被ARC删除。您应该将MPMoviePlayerController实例作为类成员。 NSNotification也解决了这个问题,因为它保留了该对象。使其成为实例变量将使通知解决方案变得冗余。

+0

谢谢!我一直在寻找答案。 –