MPMoviePlayerController - network error trap when loading a movie

Is there a way to catch exceptions (especially for network errors / no connection available) when using MPMoviePlayerController?

I am particularly concerned that after the player instance is initialized using initWithURL: you have no way to find out for some reason that the movie download failed to load.

I looked through the available documentation and realized that I could receive a notification for loadState changes through

 moviePlayerLoadStateChanged:(NSNotification*)notification. 

The problem is that loadState constants are not suitable for error handling:

 MPMovieLoadStateUnknown MPMovieLoadStatePlayable MPMovieLoadStatePlaythroughOK MPMovieLoadStateStalled 

(in case you are interested, MPMovieLoadStateStalled is this not caused during network errors for some reason?)

There is an outdated MPMoviePlayerContentPreloadDidFinishNotification , which provides a userInfo dictionary with the key "error", but nothing for iOS 3.2 and higher.

Any help would be greatly appreciated.

+6
mpmovieplayercontroller
source share
1 answer

I eventually got this sorted by subscribing to MPMoviePlayerPlaybackDidFinishNotification and watching 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

+2
source share

All Articles