jul*_*ien 3 javascript google-chrome-devtools youtube-javascript-api google-chrome-console
我可以用
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)
Run Code Online (Sandbox Code Playgroud)
另一种方法:
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)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
74 次 |
| 最近记录: |