21

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
  • 1
    This is caused by Firefox Bug #1188887 and is already fixed in Firefox beta, I believe. Currently your best bet is to use a solution like the one proposed by adeneo or to catch the exception and retry after a while. Jan 25, 2016 at 10:16

1 Answer 1

22

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);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.