【问题标题】:How to preload my movie before playing it ( MPMoviePlayerController )如何在播放之前预加载我的电影( MPMoviePlayerController )
【发布时间】:2012-03-09 11:20:08
【问题描述】:

我想预加载我的 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];
}

【问题讨论】:

    标签: objective-c ipad mpmovieplayercontroller mpmovieplayer


    【解决方案1】:

    我认为您无法加快视频加载过程。您唯一能做的就是在显示视频之前加载视频。

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

    【讨论】:

    • 完美的工作,但至少我没有加载图标:)
    • 但是仍然有几秒钟的加载时间(即使我们没有看到加载图标)我怎样才能让它直接开始......最后为什么在第一个视频上需要时间?因为它初始化了 MPMoviePlayerController 而其他人不需要初始化它还是什么? :s
    • 您可以使用 UIActivityIndi​​catorView 作为加载图标,直到视频出现。
    • 正是因为你所说的,第一个视频需要一些时间。
    猜你喜欢
    • 1970-01-01
    • 2011-04-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多