Mpmovieplayerviewcontroller has implemented some notification listening and implemented some control over mpmovieplayercontroller, such:
1. ListeningUiapplicationdidenterbackgroundnotificationNotification: Call [movieplayer stop] to stop the player.
2. ListeningMpmovieplayerplaybackdidfinishnotification(Call the stop method or send a notification when the video playback ends), call the dismiss method to remove itself.
Requirement 1: a course in the app contains several chapters. Therefore, you must load and play the next course after each chapter is played.
Problem: mpmovieplayerviewcontroller listensMpmovieplayerplaybackdidfinishnotificationNotification: After a video is played, it will call the dismissmovieplayerviewcontrolleranimated method in the listener method, and the player view will be removed directly.
Solution:
// Self is an instance object of mpmovieplayerviewcontroller.
[[Nsnotifcenter center defacenter center] removeobserver: Self name: mpmovieplayerplaybackdidfinishnotificationObject: Nil];
Requirement 2: the player is paused when the app enters the background and continues playing when it returns to the application.
Problem: mpmovieplayerviewcontroller listensUiapplicationdidenterbackgroundnotificationNotification: when entering the background, call the stop method, and then receiveMpmovieplayerplaybackdidfinishnotificationNotice: Call the dismiss method to remove the view.
solution: remove the uiapplicationdidenterbackgroundnotification and mpmovieplayerplaybackdidfinishnotification : monitors notifications and implements your own monitoring methods.
// Uiapplicationdidenterbackgroundnotification notification
-(Void) Appenterbackground :( nsnotification *) Notice {
// Record the current playback time when entering the backgroundOverlay_flags.playtimewhenenterbackground=_ Player. currentplaybacktime; [_ player pause];}
//Uiapplicationwillenterforegroundnotification notification
-(Void) Appenterforeground :( nsnotification *) Notice
{
// Set the playback speed to the normal speed and the current playback time to the time when the player enters the background.
[_ Player setcurrentplaybackrate:1.0];
[_ Player setcurrentplaybacktime: overlay_flags.playtimewhenenterbackground];
}