当前位置:网站首页>AVPlayer添加播放进度监听
AVPlayer添加播放进度监听
2022-07-17 00:09:00 【博BOBO】
其实,苹果已经提供过有关的API:和AVPlayer进度有关API
/// 添加监听.以及回调
__weak typeof(self) weakSelf = self;
[_player addPeriodicTimeObserverForInterval:CMTimeMake(1.0, 1.0) queue:dispatch_get_main_queue() usingBlock:^(CMTime time) {
/// 更新播放进度
[weakSelf updateProgress];
}];self.audioPlayer.addPeriodicTimeObserver(forInterval: CMTime.init(value: CMTimeValue(1.0), timescale: CMTimeScale(1.0)), queue: DispatchQueue.main) {
[unowned self] (time) in
let currt = CMTimeGetSeconds(time)
if Int(currt) + 1 == Int(self.audio_Model.currentDuration){
return
}
self.audio_Model.currentDuration = currt
self.pro = currt/self.audio_Model.audioDuration
self.upTimeAction(haveType: Int(currt) == Int(self.audio_Model.audioDuration))
}这个传入的参数:
CMTime就是你希望多久回调一次.
queue类似于没记错的话是下载框架中的queue.就是你希望在哪个线程回调下面的block.
block参数.CMTime time.
这个是当前播放进度.和player.currentTime.或者是player.currentItem.currentTime一致.
获取总播放时长用player.currentItem.asset.duration就行
边栏推荐
猜你喜欢

Red sun safety range 3

Countless times of stepping on the pit to install awvs

蛟分承影,雁落忘归——袋鼠云一站式全自动化运维管家ChengYing(承影)正式开源

手把手带你从零开始完整开发经典游戏【俄罗斯方块】,全部逻辑只用不到200行代码。

开源项目丨 Taier 1.1 版本正式发布,新增功能一览为快

Solve the problem that Scala cannot initialize the class of native

Introduction to software vulnerability analysis (4)

Redis suddenly slowed down?

解决scala无法对Native进行类的初始化

MapReduce
随机推荐
一文盘点估值超过1亿美元的NFT项目
软件漏洞分析入门(一)
Common asynchronous sending code writing
05_ Review object defineProperty
Iptables and snort basic configuration
紅日安全靶場3
6 寻找比目标字母大的最小字母
同学们不要全抄我的代码哈 记得改一改 要不我俩都要G
Classification and use of express Middleware
Today, the code farmer girl made notes about the life cycle and practiced the dynamic clock
03 BTC agreement
未成年人数字安全保护的问题与对策
如何建设实时开发平台,深入释放企业实时数据价值?
nmap和nikto扫描
NFT IP授权热度渐起,NFT2.0时代即将到来?
通感一体化融合的研究及其挑战
同学们 小组作业记得别抄哈 幸好只传了两道题 不要出事了
软件漏洞分析入门(五)
iptables和snort基本配置
数字藏品NFT那个平台好