AVPlayer中想关方法介绍
来源:互联网 发布:godaddy 域名续费 编辑:程序博客网 时间:2024/03/28 22:05
计算缓存
[self.itemaddObserver:selfforKeyPath:@"loadedTimeRanges"options:NSKeyValueObservingOptionNewcontext:nil];
-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSString *,id> *)change context:(void *)context
{
if (object == self.item) {
if ([keyPath isEqualToString:@"status"]) {
if (self.play.status == AVPlayerStatusReadyToPlay) {
//self.playState = ZFPlayerStatePlaying;
} else if (self.play.status ==AVPlayerStatusFailed){
//[self.maskView.activity startAnimating];
}
} else if ([keyPathisEqualToString:@"loadedTimeRanges"]) {
NSArray *loadedTimeRanges = [[self.playcurrentItem] loadedTimeRanges];
CMTimeRange timeRange = [loadedTimeRanges.firstObjectCMTimeRangeValue];//获取缓冲区域
float startSeconds = CMTimeGetSeconds(timeRange.start);
float durationSeconds = CMTimeGetSeconds(timeRange.duration);
NSTimeInterval result = startSeconds + durationSeconds;//计算缓冲总进度
NSLog(@"%f",result);
CMTime duration = self.item.duration;
CGFloat totalDuration = CMTimeGetSeconds(duration);
[self.progresssetProgress:result / totalDuration animated:NO];
}
}
}
定时
__weak typeof (self) weakSelf =self;
[self.playaddPeriodicTimeObserverForInterval:CMTimeMake(1,1) queue:dispatch_get_main_queue()usingBlock:^(CMTime time) {
if (self.isDrag) {
return ;
}
CGFloat current = CMTimeGetSeconds(time);
CGFloat total = CMTimeGetSeconds([weakSelf.item duration]);
//NSLog(@"%f--%f",current,total);
[weakSelf.slider setValue:@(current/total)forKey:@"value"];
NSInteger min = (NSInteger)current /60;
NSInteger sec = (NSInteger)current %60;
weakSelf.currentLable.text = [NSStringstringWithFormat:@"%02ld:%02ld",(long)min,(long)sec];
NSInteger min1 = (NSInteger)total /60;
NSInteger sec1 = (NSInteger)total %60;
weakSelf.totalLable.text = [NSStringstringWithFormat:@"%02ld:%02ld",(long)min1,(long)sec1];
}];
[self.playseekToTime:CMTimeMake(current,1) completionHandler:^(BOOL finished) {
self.isDrag =NO;
[self.playplay];
}];
- AVPlayer中想关方法介绍
- AVPlayer介绍
- avplayer
- AVplayer
- AVPlayer
- AVPlayer
- AVPlayer
- AVPlayer
- AVPlayer
- AVPlayer
- AVPlayer音量
- boost avplayer
- avplayer 分析
- 使用AVPlayer
- 自定义AVPlayer
- AVPlayer demo
- [绍棠] avplayer
- AVPlayer翻译
- Three.js之照相机Camera
- myBatis + SpringMVC上传、下载文件
- Android——通过findViewById自动类型转换
- 文件读写
- 约瑟夫环问题
- AVPlayer中想关方法介绍
- android学习之AIDL初探
- wins安装Java
- Collections在java中的常见用法
- 第十二周 运算符重载之复数类练习
- 网络编程知识(12)--ISO/OSI七层模型和TCP/IP四层网络模型
- 打字练习
- iOS 多线程编程之NSThread
- [BZOJ2836]魔法树(链剖+dfs序)