2016-01-23 42 views
3

在Chrome而不是Firefox中的以下工作:InvalidStateError:试图使用一个对象,是不是,或不再,可用

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

在Firefox它说

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

线路2

+0

之前,这是由[Firefox的错误#1188887(https://bugzilla.mozilla.org/show_bug引起.cgi?id = 1188887),并且已经在Firefox beta版中修复了,我相信。目前你最好的选择是使用类似于adeneo提出的解决方案,或者在一段时间后捕获异常并重试。 –

回答

6

该错误当对象(在此例中为视频)尚未载入足够的数量以便能够设置currentTime并向前跳过时发生。

你不得不等待,直到视频可以播放,您可以设置currentTime

var myVideo = document.getElementById('myVideo') 

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