实现 MPMoviePlayer 超时的最佳方法

发布于 2024-11-04 11:32:29 字数 71 浏览 0 评论 0原文

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

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

痴情 2024-11-11 11:32:29

注册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 秒。一旦该婴儿耗尽时间而没有进一步的状态更改,请执行某些操作来终止/跳过视频播放。

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.

泛滥成性 2024-11-11 11:32:29

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

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

然后检查电影状态。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文