[英]MPMoviePlayerViewController dismisses immediately
I am playing a movie via: 我正在通过以下方式播放电影:
moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL fileURLWithPath:asset.filepath]];
//[[vc moviePlayer] prepareToPlay];
[self presentViewController:moviePlayer animated:YES completion:NULL];
The controller shows up but immediately after, dismisses itself. 控制器显示出来,但之后立即解散。 What am I doing wrong? 我究竟做错了什么? Thanks! 谢谢!
you have to remove MPMoviePlayerPlaybackDidFinishNotification
NSNotificationCenter
like :- 您必须像这样删除MPMoviePlayerPlaybackDidFinishNotification
NSNotificationCenter
:
moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL fileURLWithPath:asset.filepath]];
//[[vc moviePlayer] prepareToPlay];
[[NSNotificationCenter defaultCenter] removeObserver:moviePlayer name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayer.moviePlayer];
[self presentViewController:moviePlayer animated:YES completion:NULL];
Becouse MPMoviePlayerViewController
automatically registers itself to the NSNotificationCenter
upon creation. 因为MPMoviePlayerViewController
在创建后会自动将其注册到NSNotificationCenter
。 You have to first remove this registration and it will stop dismissing itself automatically. 您必须先删除此注册,它会停止自动退出。 Hope its helps you 希望它对您有帮助
Please check Bellow Link:- 请检查波纹管链接:-
http://josebolanos.wordpress.com/2011/09/28/dismissing-mpmovieplayerviewcontroller-the-right-way/ http://josebolanos.wordpress.com/2011/09/28/dismissing-mpmovieplayerviewcontroller-the-right-way/
Had a similar issue while trying to play audio. 尝试播放音频时遇到了类似的问题。 Try setting your movie player as a property with a strong reference. 尝试将电影播放器设置为具有强参考性的属性。
检查您的-(void)viewWillDisappear:(BOOL)animated{
方法,如果您要dismissing
moviePlayer
那么这就是原因。
From the docs: 从文档:
" To present a movie player view controller modally, you typically use the presentMoviePlayerViewControllerAnimated:
method. This method is part of a category on the UIViewController
class and is implemented by the Media Player framework. The presentMoviePlayerViewControllerAnimated:
method presents a movie player view controller using the standard transition animations for presenting video content. To dismiss a modally presented movie player view controller, call the dismissMoviePlayerViewControllerAnimated
method." “要以模态方式显示电影播放器视图控制器,通常使用presentMoviePlayerViewControllerAnimated:
方法。此方法是UIViewController
类的类别的一部分,由Media Player框架实现presentMoviePlayerViewControllerAnimated:
方法使用以下presentMoviePlayerViewControllerAnimated:
呈现电影播放器视图控制器:用于呈现视频内容的标准过渡动画。要关闭以模态呈现的电影播放器视图控制器,请调用dismissMoviePlayerViewControllerAnimated
方法。
You can't use the normal modal presentation method. 您不能使用常规的模态表示方法。 Must use the method provided by media player framework in UIViewContoller
category. 必须使用UIViewContoller
类别中的媒体播放器框架提供的方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.