【发布时间】:2011-05-02 09:34:52
【问题描述】:
我有从流中加载电影的 MPMoviePlayer。我用定时器实现了 15 秒的超时。但是是否有其他更好的方法来实现没有计时器的超时?
【问题讨论】:
标签: iphone objective-c ios4 mpmovieplayercontroller mpmovieplayer
我有从流中加载电影的 MPMoviePlayer。我用定时器实现了 15 秒的超时。但是是否有其他更好的方法来实现没有计时器的超时?
【问题讨论】:
标签: iphone objective-c ios4 mpmovieplayercontroller mpmovieplayer
注册MPMoviePlayerLoadStateDidChangeNotification。在其处理程序中,检查当前负载状态并屏蔽 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];
然后检查电影状态。
【讨论】: