实现MPMoviePlayer超时的最佳方式

问题描述:

我有从流加载电影的MPMoviePlayer。我用计时器在15秒内实现了超时。但是,有没有其他更好的方法来实现没有定时器的超时?实现MPMoviePlayer超时的最佳方式

注册为MPMoviePlayerLoadStateDidChangeNotification。在其处理程序中,检查当前的loadstate并掩盖MPMovieLoadStateStalled

- (void)MPMoviePlayerLoadStateDidChange:(NSNotification *)notification 
{ 
    //is the player stalled, hence possibly starving? 
    if ((movieController_.loadState & MPMovieLoadStateStalled) == MPMovieLoadStateStalled) 
    { //yes->do something 
     NSLog(@"hey there, I am starving to death here"); 
    } 
} 

您可能想要在上面的if-子句中注册一个定时器 - 例如,持续10秒。一旦宝宝没有进一步的状态改变时间,请做一些终止/跳过视频播放。

我不确定,但我认为可以使用performSelector作为计时器吗?

[self performSelector:@selector(checkTimeout:) withObject:theMovie afterDelay:15]; 

然后检查电影状态。