实现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];
然后检查电影状态。