Avoid automatic dismiss after mpmovieplayerviewcontroller is played, and automatically dismiss when entering the background

Source: Internet
Author: User

 

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];
}

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.