MPMoviePlayerViewController done button is not removing the player

 ̄綄美尐妖づ 提交于 2020-01-16 19:08:09

问题


My app has to be work in Ios5 and later Versions. I am adding MPMoviePlayerViewController to mainWindow When clicking on a button.the Done button of moviePlayerController is not removing the moviePlayerController from window.

My code is

    NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle]
                                     pathForResource:@"001 ATSW" ofType:@"m4v"]];
   self.player =  [[MPMoviePlayerViewController alloc]
                initWithContentURL:url];
[[NSNotificationCenter defaultCenter] addObserver:self         selector:@selector(videoPlayBackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];

[self.player.view setFrame:[UIScreen mainScreen].bounds];
[[[UIApplication sharedApplication] keyWindow] addSubview:self.player.view];
[[self.player moviePlayer] play];
  }
 -(void)videoPlayBackDidFinish:(NSNotification*)notification  {

  [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:nil];

[self.player.moviePlayer stop];
self.player = nil;
[self.player.view removeFromSuperview];
  }

How to remove the moviePlayerController on clicking the Done Button.

Any help please.


回答1:


As stated in the documentation:

To dismiss a modally presented movie player view controller, call the dismissMoviePlayerViewControllerAnimated method.

As with other preconfigured controllers by Apple (such as the mail compose controller or image picker controller), you are responsible to dismiss the controller.




回答2:


What you'll probably need to do is to actually using the

presentMoviePlayerViewControllerAnimated:(MPMoviePlayerViewController *)playerVC

method to present the MPMoviewPlayerViewController, and not inserting the view directly. As MPMoviewPlayerViewController is trying to dismiss itself when pressing the done button. And from what I can see there's no good way to listen for that and do it like when the movie finishes.

It might depend on how your app is built, but with something like

[[[[UIApplication sharedApplication] keyWindow] rootViewController] presentMoviePlayerViewControllerAnimated:player];

You should be able to replace all of the code to insert a view maualy, and then just using

[[[[UIApplication sharedApplication] keyWindow] rootViewController] dismissMoviePlayerViewControllerAnimated];


来源:https://stackoverflow.com/questions/14773338/mpmovieplayerviewcontroller-done-button-is-not-removing-the-player

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!