3

我可以暂停视频 globalThis.ytPlayerUtilsVideoTagPoolInstance.l[0].pause()

我可以得到视频的当前时间globalThis.ytPlayerUtilsVideoTagPoolInstance.l[0].currentTime

视频到达时如何自动触发暂停currentTime > 180

4

1 回答 1

5

一个简单的方法是轮询。

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)
于 2018-12-26T14:05:12.120 回答