MPMoviePlayerController - catching network errors when loading a movie

梦想的初衷 提交于 2020-01-13 09:42:52

问题


Is there a way of catching exceptions (particularly for network errors / no connection available) when using a MPMoviePlayerController?

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.

Problem is the loadState constants available don't cater for error handling:

MPMovieLoadStateUnknown
MPMovieLoadStatePlayable
MPMovieLoadStatePlaythroughOK
MPMovieLoadStateStalled

(in case you are wondering, MPMovieLoadStateStalled this doesn't get called during network errors for some reason?)

There's a deprecated MPMoviePlayerContentPreloadDidFinishNotification that provides a userInfo dictionary with an "error" key but nothing for iOS 3.2 and above.

Any help would be very much appreciated.


回答1:


In the end I got this sorted by subscribing to MPMoviePlayerPlaybackDidFinishNotification and watching for MPMovieFinishReasonPlaybackError.

More details here https://developer.apple.com/library/ios/documentation/MediaPlayer/Reference/MPMoviePlayerController_Class/Reference/Reference.html#//apple_ref/doc/uid/TP40006953-CH3-SW17



来源:https://stackoverflow.com/questions/4150085/mpmovieplayercontroller-catching-network-errors-when-loading-a-movie

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