gpt4 book ai didi

javascript - 当

转载 作者:行者123 更新时间:2023-12-03 00:35:19 25 4
gpt4 key购买 nike

我想使用 Firefox 扩展程序显示视频的当前百分比。

我知道我可以使用 Youtube Player API 获取当前时间和持续时间:

player = document.getElementById('movie_player')
currentTime = player.getCurrentTime()
duration = player.getDuration()

我可以使用 appendChildinsertBefore 将节点添加到 DOM。

但我不明白如何随着时间的推移定期更新 DOM。

我试图了解 Youtube 播放器如何使用检查器更新时间显示,但它对我没有帮助:

Time display

Inspector

我想我应该以某种方式使用事件,但我不知道在没有用户干预的情况下可以定期触发什么事件(点击、悬停...)。

最佳答案

听起来您正在寻找 timeupdate Media Event :

The time indicated by the element's currentTime attribute has changed.

const vid = document.querySelector('video')

vid.addEventListener('timeupdate', e => {
console.log(vid.currentTime)
})
<video autoplay width="320" height="240" controls>
<source src="http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ForBiggerFun.mp4" type="video/mp4">
</video>

关于javascript - 当<video>时间发生变化时收到通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53687217/

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