MPMoviePlayerViewController完成按钮未删除播放器 [英] MPMoviePlayerViewController done button is not removing the player

查看:262
本文介绍了MPMoviePlayerViewController完成按钮未删除播放器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用必须在Ios5和更高版本中可以使用.我将MPMoviePlayerViewController添加到mainWindow时,单击按钮.moviePlayerController的完成"按钮不会从窗口中删除moviePlayerController.

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.

我的代码是

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

如何在单击完成"按钮时删除moviePlayerController.

How to remove the moviePlayerController on clicking the Done Button.

请帮忙.

推荐答案

您可能需要做的是实际使用

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

presentMoviePlayerViewControllerAnimated:(MPMoviePlayerViewController *)playerVC

方法可显示MPMoviewPlayerViewController,而不是直接插入视图.由于MPMoviewPlayerViewController尝试在按下完成"按钮时自行关闭.而且据我所知,没有什么好办法可以像电影结束时那样听和做.

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

这篇关于MPMoviePlayerViewController完成按钮未删除播放器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆