// 创建定时器
- (void)createTimer
{
__weak typeof(self) weakSelf = self;
self.timeObserve = [self.player addPeriodicTimeObserverForInterval:CMTimeMakeWithSeconds(1, 1) queue:nil usingBlock:^(CMTime time){
AVPlayerItem *currentItem = weakSelf.playerItem;
NSArray *loadedRanges = currentItem.seekableTimeRanges;
if (loadedRanges.count > 0 && currentItem.duration.timescale != 0) {
NSInteger currentTime = (NSInteger)CMTimeGetSeconds([currentItem currentTime]);
CGFloat totalTime = (CGFloat)currentItem.duration.value / currentItem.duration.timescale;
CGFloat value = CMTimeGetSeconds([currentItem currentTime]) / totalTime;
[weakSelf.controlView zf_playerCurrentTime:currentTime totalTime:totalTime sliderValue:value];
if (_playTimeBlock != nil) {
weakSelf.playTimeBlock(currentTime,totalTime);
}
}
}];
}
网友评论