我可以暂停视频
globalThis.ytPlayerUtilsVideoTagPoolInstance.l[0].pause()
我可以得到视频的当前时间globalThis.ytPlayerUtilsVideoTagPoolInstance.l[0].currentTime
视频到达时如何自动触发暂停currentTime > 180
?
我可以暂停视频
globalThis.ytPlayerUtilsVideoTagPoolInstance.l[0].pause()
我可以得到视频的当前时间globalThis.ytPlayerUtilsVideoTagPoolInstance.l[0].currentTime
视频到达时如何自动触发暂停currentTime > 180
?
一个简单的方法是轮询。
const player = globalThis.ytPlayerUtilsVideoTagPoolInstance.l[0]
setTimeout(function polling() {
if (player.currentTime < 180)
setTimeout(polling, 1000)
else
player.pause()
}, 1000)
另一种方法:
const player = globalThis.ytPlayerUtilsVideoTagPoolInstance.l[0]
const timer = setInterval(() => { // no need of named function as no 'async recursion' is needed
if (player.currentTime >= 180) {
player.pause()
clearInterval(timer)
}
}, 1000)