美文网首页
视频播放时的定时器

视频播放时的定时器

作者: 耽于幽夜 | 来源:发表于2018-06-22 10:40 被阅读0次

// 创建定时器

- (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);

            }

        }

    }];

}

相关文章

网友评论

      本文标题:视频播放时的定时器

      本文链接:https://www.haomeiwen.com/subject/hrjzfftx.html