IOS: How to prevent the disappearance of the video player when going to the background?

I have mpMoviePlayerViewController that is transmitting video from a remote server. Everything works well, but I noticed that if I send the application to the background (by clicking the "home" button), when I open it again, mpMoviePlayerViewController will stop playing and disappear.

Here is my code:

-(void)playVideo:(NSURL *)url{ mpViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:url]; if (mpViewController){ [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(myMovieFinishedCallback:) name: MPMoviePlayerPlaybackDidFinishNotification object: mpViewController.moviePlayer]; [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(myMoviePreloadCallback:) name: MPMoviePlayerLoadStateDidChangeNotification object: mpViewController.moviePlayer]; } } -(void) myMoviePreloadCallback: (NSNotification*) aNotification{ [self performSelectorOnMainThread:@selector(myMoviePreloadCallbackMainThread) withObject:nil waitUntilDone:NO]; } -(void)myMoviePreloadCallbackMainThread{ [[NSNotificationCenter defaultCenter] removeObserver: self name: MPMoviePlayerLoadStateDidChangeNotification object: mpViewController.moviePlayer]; [self presentMoviePlayerViewControllerAnimated:mpViewController]; [mpViewController.moviePlayer play]; } -(void) myMovieFinishedCallback: (NSNotification*) aNotification { [[NSNotificationCenter defaultCenter] removeObserver: self name: MPMoviePlayerPlaybackDidFinishNotification object: mpViewController.moviePlayer]; [mpViewController.moviePlayer stop]; [self dismissMoviePlayerViewControllerAnimated]; [mpViewController release]; } 

Is there a way to get the player to continue the game from where he left off?

+4
source share

Source: https://habr.com/ru/post/1381466/


All Articles