问题
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