I have an app that plays video clips using a subclassed MPMoviePlayerViewController, and I want to ensure the movie player is dismissed when the user leaves the app (when it enters the background).
This is necessary as when they re-enter the app, it doesn’t seem to load the Movie URL correctly, so they get a blank movie player that is constantly loading.
Normally, I dismiss the Movie Player using [self dismissMoviePlayerViewControllerAnimated] when the Done button is pressed.
What is the proper way to dismiss the player when the application resigns active (or moves to background)?
Ok I ended up using Notifications to “cleanup” my MPMoviePlayerViewController when the application is about to be sent to the background. This allows me to detect when the app is about to be sent to the background from a class other than my app delegate.
So when I create the movie player, I add the observer to call my “cleanup” function when the application is sent to the background.
(Side Note – I also use an observer that prevents the movie view from closing automatically after the video finishes. That way the user has to press the “Done” button. That button also calls the moviePlayerCleanup method. This ensure that the observer is always removed properly)