获取视频缓存进度
作者:
路这么长 | 来源:发表于
2016-11-17 10:24 被阅读42次- (void)addNotificationCenters {
//注册观察者监听是否完成播放
[[NSNotificationCenterdefaultCenter]addObserver:selfselector:@selector(moviePlayDidEnd)name:AVPlayerItemDidPlayToEndTimeNotificationobject:nil];
//监控状态属性,注意AVPlayer也有一个status属性,通过监控它的status也可以获得播放状态
[self.playV.playItemaddObserver:selfforKeyPath:@"status"options:NSKeyValueObservingOptionNewcontext:nil];
//监控网络加载情况属性
[self.playV.playItemaddObserver:selfforKeyPath:@"loadedTimeRanges"options:NSKeyValueObservingOptionNewcontext:nil];
}
//监听执行的方法(缓冲进度)
- (void)observeValueForKeyPath:(NSString*)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void*)context {
AVPlayerItem*playerItem = object;
if([keyPathisEqualToString:@"loadedTimeRanges"]) {
NSArray*loadedTimeRanges = [[self.playV.playercurrentItem]loadedTimeRanges];
CMTimeRangetimeRange = [loadedTimeRanges.firstObjectCMTimeRangeValue];//获取缓冲区域
floatstartSeconds =CMTimeGetSeconds(timeRange.start);
floatdurationSeconds =CMTimeGetSeconds(timeRange.duration);
NSTimeIntervalresult = startSeconds + durationSeconds;//计算缓冲总进度
NSLog(@"当前缓冲%.2f", result);
}
}
本文标题:获取视频缓存进度
本文链接:https://www.haomeiwen.com/subject/fpddpttx.html
网友评论