MPMoviePlayerController-加载电影时捕获网络错误 [英] MPMoviePlayerController - catching network errors when loading a movie
问题描述
有没有一种捕获异常的方法(尤其是对于网络错误) /没有可用的连接)在使用MPMoviePlayerController时?
Is there a way of catching exceptions (particularly for network errors / no connection available) when using a MPMoviePlayerController?
我特别担心的是,一旦使用initWithURL:
初始化了播放器实例,您就无法知道影片加载是否由于某种原因而失败.
I am particularly concerned that once an instance of the player is initialised with initWithURL:
you have no way of knowing whether the movie load has failed for some reason.
我已经查看了可用的文档,意识到可以得到一份 通过
I have reviewed the available documentation and realise I can get a notification for loadState changes through
moviePlayerLoadStateChanged:(NSNotification*)notification.
问题是可用的loadState常量不能满足错误处理的要求:
Problem is the loadState constants available don't cater for error handling:
MPMovieLoadStateUnknown
MPMovieLoadStatePlayable
MPMovieLoadStatePlaythroughOK
MPMovieLoadStateStalled
(如果您想知道,MPMovieLoadStateStalled出于某种原因在网络错误期间不会被调用?)
(in case you are wondering, MPMovieLoadStateStalled this doesn't get called during network errors for some reason?)
有一个已弃用的MPMoviePlayerContentPreloadDidFinishNotification
,它为userInfo词典提供了错误"键,但对于iOS 3.2及更高版本则不提供任何功能.
There's a deprecated MPMoviePlayerContentPreloadDidFinishNotification
that provides a userInfo dictionary with an "error" key but nothing for iOS 3.2 and above.
任何帮助将不胜感激.
推荐答案
最后,我通过订阅MPMoviePlayerPlaybackDidFinishNotification并观察MPMovieFinishReasonPlaybackError来进行排序.
In the end I got this sorted by subscribing to MPMoviePlayerPlaybackDidFinishNotification and watching for MPMovieFinishReasonPlaybackError.
此处有更多详细信息 查看全文