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