addObserver
来源:互联网 发布:淘宝吊带碎花长裙 编辑:程序博客网 时间:2024/06/16 11:21
}
#pragma mark- KVO回调方法
-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context{
//判断被观察的对象是否为对应的媒体对象,并且观察的属性为status字段
if (object == self.myPlayerView.player.currentItem && [keyPath isEqualToString:@"status"])
{
/*
AVPlayerStatusUnknown,
AVPlayerStatusReadyToPlay,
AVPlayerStatusFailed
*/
//判断状态是否转变为可播放状态
if (self.myPlayerView.player.currentItem.status == AVPlayerStatusReadyToPlay)
{
/*
//CMTime专门用于表示电影时间
//CMTimeMake(已经播放到第几帧, 1秒钟内播放的总帧);
CMTimeMake(50, 2);
*/
//总秒数
NSInteger totalSeconds = self.myPlayerView.player.currentItem.duration.value / self.myPlayerView.player.currentItem.duration.timescale;
//设置进度条的最大值
self.progressSlider.maximumValue = totalSeconds;
//设置显示总时间大小的Label内容
self.totalTimeLabel.text = [NSString stringWithFormat:@"%02ld:%02ld:%02ld",totalSeconds/3600,totalSeconds%3600/60,totalSeconds%60];
}
//监测进度
/*
参数1:监测的间隔时间
参数2:使用的队列(GCD内容,暂时置为nil)
参数3:回调block
*/
[self.myPlayerView.player addPeriodicTimeObserverForInterval:CMTimeMake(1, 1) queue:nil usingBlock:^(CMTime time)
{
//CMTime time :目前播放的进度为time
//设置进度条进度
self.progressSlider.value = time.value / time.timescale;
//设置显示进度秒数的label内容
self.playTimeLabel.text = [NSString stringWithFormat:@"%02ld:%02ld:%02ld",(NSInteger)self.progressSlider.value/3600,(NSInteger)self.progressSlider.value%3600/60,(NSInteger)self.progressSlider.value%60];
}];
}
}
- (IBAction)progressSliderAction:(UISlider *)sender {
//拖拽进度条改变播放进度
[self.myPlayerView.player.currentItem seekToTime:CMTimeMake(sender.value, 1)];
}
- addObserver
- objective-c NSNotificationCenter,addObserver
- addObserver与removeObserver不是一对一对称的
- addObserver和postNotification函数传递函数的区别
- Cocos2d-x中,addObserver如何传递消息
- [NSNotificationCenter defaultCenter] addObserver 时 object的意义。
- addObserver为对象某个属性添加监听
- [[NSNotificationCenterdefaultCenter] addObserver时object的意义
- iphone 消息处理事件 postNotificationName和addObserver的调用
- iphone 消息处理事件 postNotificationName和addObserver的调用
- iOS: NSNotificationCenter的方法addObserver:selector:name:object:
- CCNotificationCenter(中心类addObserver postNotification m_observers. CCNoti..Observer类 performSelector)
- NSNotificationCenter 中的addObserver和addObserverForName的释放问题。
- addObserver:forKeyPath:options:context: Registers anObserver to receive KVO notifications
- KVO 和 NSNotificationcenter addObserver 和removeObserve成对出现的原因
- NSNotificationCenter 中的addObserver和addObserverForName的释放问题。
- NSMutableArray的监听问题及解决方案:[<__NSArrayM 0x4e17fd0 addObserver:forKeyPath:options:context] is not suppo
- 关于[[NSNotificationCenter defaultCenter] addObserver不remove后续又收到通知crash问题
- 面试题1:类的赋值运算符函数
- collectionView(xib)
- unity android设备上查看log输出
- 刷题第七天:南邮NOJ【1015求最大公约数和最小公倍数】
- div 水平居中的一种方法
- addObserver
- C++类和动态内存分配(1)
- 【PAT】【GPLT】【2016 天梯赛 初赛】 L1-020 帅到没朋友
- 回到主线程三种常用方法
- 归解档
- c++第六次作业
- jQuery EasyUI时间戳自定义时间显示格式类型
- C++11多线程之条件变量
- 安装VMware,创建ubuntu linux虚拟机,使用Secure连接虚拟机