Best way to implement MPMoviePlayer timeout

别来无恙 提交于 2019-12-08 07:57:50

问题


I have MPMoviePlayer that load movie from stream. I implemented timeout on 15 seconds with timers. But is there maybe some other better way to implement timeout without timer?


回答1:


Register for the MPMoviePlayerLoadStateDidChangeNotification. Within its handler, check the current loadstate and mask out the 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");
    }
}

You may want to register a timer within the upper if-clause - e.g. 10seconds. Once that baby runs out of time without further state-changes, do something to terminate / skip the video playback.




回答2:


I'm not sure but i think it's possible to use performSelector as timer?

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

and then check for the movie state.



来源:https://stackoverflow.com/questions/5855562/best-way-to-implement-mpmovieplayer-timeout

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!