InvalidStateError: An attempt was made to use an object that is not, or is no longer, usable
InvalidStateError: An attempt was made to use an object that is not, or is no longer, usable
以下内容适用于 Chrome 但不适用于 Firefox:
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 行。
当对象(在本例中为视频)的加载量不足以设置 currentTime
并向前跳时,就会发生该错误。
您必须等到视频可以播放后才能设置 currentTime
var myVideo = document.getElementById('myVideo')
myVideo.addEventListener('canplaythrough', function() {
myVideo.currentTime = 570;
}, false);
以下内容适用于 Chrome 但不适用于 Firefox:
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 行。
当对象(在本例中为视频)的加载量不足以设置 currentTime
并向前跳时,就会发生该错误。
您必须等到视频可以播放后才能设置 currentTime
var myVideo = document.getElementById('myVideo')
myVideo.addEventListener('canplaythrough', function() {
myVideo.currentTime = 570;
}, false);