避免MPMoviePlayerViewController播放完毕后自

避免MPMoviePlayerViewController播放完毕后自动dismiss

阅读103次 2012/11/28 15:23:59

MPMoviePlayerViewController已经实现了一些通知的监听并对MPMoviePlayerController实现了一些控制,比如:


1. 监听UIApplicationWillResignActiveNotification通知,调用[movieplayer pause],使播放器暂停。

2. 监听UIApplicationDidBecomeActiveNotification通知,调用[movieplayer play],使播放器继续播放。

3. 监听UIApplicationDidEnterBackgroundNotification通知,调用[movieplayer stop],播放器停止。

4. 监听MPMoviePlayerPlaybackDidFinishNotification(调用stop方法或视频播放结束时发送通知)通知,调用dismiss方法移除自身


需求1:app中一个课程包含若干个章节,所以每次播放完一个章节后要求直接加载播放下一个课程。

遇到问题:由于MPMoviePlayerViewController监听了MPMoviePlayerPlaybackDidFinishNotification通知,当一个视频播放完毕,它会在监听方法中       调用dismissMoviePlayerViewControllerAnimated方法,播放器视图就直接移除了。

解决方法:

// self为MPMoviePlayerViewController的一个实例对象。
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];

 

需求2: app进入后台时播放器暂停,回到应用时继续播放

遇到问题:由于MPMoviePlayerViewController监听了UIApplicationDidEnterBackgroundNotification通知,当进入后台时,调用stop方法,随后接收      到MPMoviePlayerPlaybackDidFinishNotification通知,调用dismiss方法移除自身视图。

解决方法:移除MPMoviePlayerViewController对UIApplicationDidEnterBackgroundNotification和MPMoviePlayerPlaybackDidFinishNotification      通知的监听,并实现自己的监听方法

// UIApplicationDidEnterBackgroundNotification通知
- (void)appEnterBackground:(NSNotification*)notice {
  // 进入后台时记录当前播放时间 overlay_flags.playTimeWhenEnterBackground
= _player.currentPlaybackTime; [_player pause]; }
//
UIApplicationWillEnterForegroundNotification通知
- (void)appEnterForeground:(NSNotification*)notice
{
  // 设置播放速率为正常速度,设置当前播放时间为进入后台时的时间
[_player setCurrentPlaybackRate:1.0];
[_player setCurrentPlaybackTime:overlay_flags.playTimeWhenEnterBackground];
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值