On my iPhone i'm playing video/audio files in fullscreen mode. When the video/audio file reached its end then the following method is triggered:
- (void) movieFinishedCallback:(NSNotification*) aNotification {
MPMoviePlayerController *player = [aNotification object];
[player stop];
[[NSNotificationCenter defaultCenter]
removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:player];
[player autorelease];
[moviePlayer.view removeFromSuperview];
NSLog(@"stopped?");
}
That works fine! But the problem is when i press on the "Done" button when the video/audio file is still playing. Then this method doesn't get triggered...
Anyone any idea how to catch the event when the "Done" button is pressed? Because right now media player stays in the view. Its not disappearing.
SUCCESSFULLY TESTED IN iOS7 AND iOS8
Check and remove earlier notification observer if any for
MPMoviePlayerPlaybackDidFinishNotification
.Dismiss controller
You'r Done !!!
Apple's documentation is very poor on this matter. It suggests to listen for MPMoviePlayerDidExitFullscreenNotification (or WillExit...) and NOT for MPMoviePlayerDidFinishNotification as it doesn't fire when the user taps Done. This is entirely not true! I've just tested it on Xcode 6.0 with iPad Simulator (iOS 7.1 + 8.0) and only MPMoviePlayerDidFinishNotification is fired when DONE is tapped.
My compliments to user523234 who got it right on one of the comments above.
Register the following observer
Swift version, for anyone who's interested:
Notification handler:
Wow, so many wrong approaches. The answer is this simple:
Check this link if you have a minute: https://developer.apple.com/library/prerelease/ios/documentation/MediaPlayer/Reference/UIViewController_MediaPlayer_Additions/index.html
Happy coding! Z.
It worked for me on iPad when I listen to
MPMoviePlayerWillExitFullscreenNotification
.And selector method: