InvalidStateError: An attempt was made to use an object that is not, or is no longer, usable

对着背影说爱祢 提交于 2019-12-10 01:26:42

问题


The following works in Chrome but not Firefox:

var myVideo = document.getElementById('myVideo')
myVideo.currentTime = 570
<video id="myVideo" controls>
<source src="myVideo.mp4" type="video/mp4">
</video>

In Firefox it says

InvalidStateError: An attempt was made to use an object that is not, or is no longer, usable

for line 2.


回答1:


That error occurs when the object, in this case the video, hasn't loaded enough to be able to set the currentTime and skip forward.

You'd have to wait until the video can be played before you can set the currentTime

var myVideo = document.getElementById('myVideo')

myVideo.addEventListener('canplaythrough', function() {
    myVideo.currentTime = 570;
}, false);


来源:https://stackoverflow.com/questions/34970272/invalidstateerror-an-attempt-was-made-to-use-an-object-that-is-not-or-is-no-lo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!