我可以暂停视频
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)
关于javascript - 达到 3 分钟后从 chrome 控制台暂停 YouTube 视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53933106/