Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MPMoviePlayerController - catching network errors when loading a movie

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.

like image 370
Rog Avatar asked Nov 10 '10 23:11

Rog


1 Answers

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

like image 67
Rog Avatar answered Oct 11 '22 13:10

Rog