Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 635
Phillip Senn Avatar asked Jan 23 '16 23:01

Phillip Senn


1 Answers

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);
like image 188
adeneo Avatar answered Nov 12 '22 23:11

adeneo