问题描述
我正在尝试与Chrome中的第三方html5视频播放器进行互动。我能够获得对它的有效引用:
I am trying to interact with a 3rd-party html5 video player in Chrome. I am able to obtain a valid reference to it thusly:
document.getElementsByTagName("video")[1]
...而 readyState
是4,所以它是好的。
...and the readyState
is 4, so it's all good.
我可以成功(并且有预期的结果)致电:
I can successfully (and with expected result) call:
document.getElementsByTagName("video")[1].play();
document.getElementsByTagName("video")[1].pause();
但是当我打电话时:
document.getElementsByTagName("video")[1].currentTime = 500;
...视频冻结,并且没有前进到新的 currentTime的
。视频持续时间远远超过500秒,因此它应该能够前进到那个位置。我已尝试过500次以外的其他时间,都有相同的结果。如果我检查 currentTime
,那么我刚设置的是正确的。但它实际上并没有去那里。此外,我无法再与视频互动。它在我尝试设置 currentTime后忽略对
。 play()
或 pause()
的任何调用
...the video freezes and it doesn't advance to the new currentTime
. The video duration is much longer than 500 seconds, so it should be able to advance to that spot. I have tried other times besides 500, all with same result. If I examine currentTime
, it is correct as to what I just set. But it doesn't actually go there. Also I can no longer interact with the video. It ignores any calls to play()
or pause()
after I try to set currentTime
.
之前我拨打 currentTime
,当我打电话给 play()
我得到了这个有效的保证,其他一切仍然有效:
Before I call currentTime
, when I call play()
I get this valid promise back, and everything else still works:
之后我拨打 currentTime
,当我拨打 play()
,我得到了这个破碎的承诺,现在该视频对象无效:
After I call currentTime
, when I call play()
, I get this broken promise back, and now nothing works on that video object:
如果您有一个帐户,只需在Chrome开发者控制台中尝试,您就可以轻松地在任何视频中观察此行为
If you have a Hulu account you can easily observe this behavior on any video by simply trying it in the Chrome developer console.
编辑:有人向我指出,跳过很长时间的休息时间,但跳过短距离确实很有效。可能与穿插的商业广告有关。
EDIT: It was pointed out to me that skipping very much ahead breaks, but skipping a short distance actually works well. Could be related to commercials interspersed.
推荐答案
尝试下面的代码,它会先暂停然后再设置你的位置然后再玩
Try below code, it will first pause then set your position then again play
document.getElementsByTagName("video")[1].pause();
document.getElementsByTagName("video")[1].currentTime = 500;
document.getElementsByTagName("video")[1].play();
这篇关于HTML5视频 - 设置video.currentTime打破播放器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!