iphone - MPMoviePlayerViewController 立即关闭

标签 iphone ios objective-c cocoa-touch

我正在通过以下方式播放电影:

moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL fileURLWithPath:asset.filepath]];

//[[vc moviePlayer] prepareToPlay];
[self presentViewController:moviePlayer animated:YES completion:NULL];

Controller 出现,但紧随其后自行消失。我究竟做错了什么?谢谢!

最佳答案

你必须删除 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];

因为 MPMoviePlayerViewController 在创建时自动将自己注册到 NSNotificationCenter。您必须先删除此注册,它会自动停止自行关闭。希望对你有帮助

请检查以下链接:-

http://josebolanos.wordpress.com/2011/09/28/dismissing-mpmovieplayerviewcontroller-the-right-way/

关于iphone - MPMoviePlayerViewController 立即关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16769027/

相关文章:

ios - 在 UITableView 中访问多维数组值

ios - 集成 Nuance Dragon Mobile 时架构 x86_64 的 undefined symbol

ios - Xcode 滑动和删除

iphone - 初始化方法模式

iphone - 使用事件指示器和标签显示警报(可变)

objective-c - 滚动时通过 UIScrollView 的 subview 处理点击事件

ios - 了解具有泛型约束的泛型

ios - UIBezierPath 未按预期更新

iphone - Facebook SDK iOS - 授权应用内?

iphone - 如何确定和解释 CGImage 的像素格式