gpt4 book ai didi

ios - 检测 AVPlayer 何时达到总播放时间的特定百分比?

转载 作者:搜寻专家 更新时间:2023-11-01 06:31:42 25 4
gpt4 key购买 nike

当用户播放视频时,我试图弄清楚用户何时达到一定的播放百分比。

例如,用户正在播放视频,我想在用户播放到 50% 时显示一些 View 。

更多说明,有没有办法在 50% 发生时设置“监听器/观察器”?

最佳答案

最好的观察方式可能是使用来自 docsperiodTimeObserver :

func addPeriodicTimeObserver() {
// Invoke callback every half second
let interval = CMTime(seconds: 0.5,
preferredTimescale: CMTimeScale(NSEC_PER_SEC))
// Queue on which to invoke the callback
let mainQueue = DispatchQueue.main
// Add time observer
timeObserverToken =
player.addPeriodicTimeObserver(forInterval: interval, queue: mainQueue) {
[weak self] time in
// Check whether the time has reached half of duration
}
}

关于ios - 检测 AVPlayer 何时达到总播放时间的特定百分比?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46432851/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com