如何在播放之前预装我的电影(MPMoviePlayerController)

时间:2012-03-09 11:20:08

标签: objective-c ipad mpmovieplayercontroller mpmovieplayer

我想预装我的MPMoviePlayerController,问题是MPMoviePlayerController花了太多时间准备好所以加载图标显示然后显示视频,如果我播放另一个视频后直接播放但不是第一个时间...... :(

我知道有这样的:MPMoviePlayerLoadStateDidChangeNotification但我不知道它是如何工作的。

这是我的代码:

- (void) startSlideShow:(NSString *)nameFile
{    
    NSURL *url = [NSURL fileURLWithPath:nameFile];
    MPMoviePlayerController *moviePlayer = 
    [[MPMoviePlayerController alloc] initWithContentURL:url];
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(moviePlayBackDidFinish:)
                                                 name:MPMoviePlayerPlaybackDidFinishNotification
                                               object:moviePlayer];

    moviePlayer.view.frame = CGRectMake(0, 0, 768, 1024);
    moviePlayer.controlStyle = MPMovieControlStyleDefault;

    [self.view addSubview:moviePlayer.view];
    CATransition *animation = [CATransition animation];
    [animation setDuration:0.5];
    [animation setType:kCATransitionFade];
    [animation setSubtype:kCATransitionFromLeft];
    [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];

    [[self.view layer] addAnimation:animation forKey:@"SwitchToView1"];
    [moviePlayer setFullscreen:YES animated:YES];
   }


-(void)moviePlayBackDidFinish: (NSNotification*)notification
{ 
    MPMoviePlayerController *moviePlayer = [notification object];

    [[NSNotificationCenter defaultCenter] removeObserver:self      
                                                    name:MPMoviePlayerPlaybackDidFinishNotification
                                                  object:moviePlayer];

    if ([moviePlayer respondsToSelector:@selector(setFullscreen:animated:)])
    {
       [moviePlayer.view removeFromSuperview];
    }
    [self checkResources];
}

1 个答案:

答案 0 :(得分:0)

我认为你不能加快视频加载过程。您唯一能做的就是比显示视频更快地加载视频。

对于玩家状态通知,请在此处查看我的回答: https://stackoverflow.com/a/9073946/624808