问题
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