本文介绍了InvalidStateError:尝试使用一个不可用或不再可用的对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下内容适用于Chrome,但不适用于Firefox:

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>

在Firefox中显示

In Firefox it says

第2行.

推荐答案

当对象(在本例中为视频)未加载到足以设置currentTime并向前跳过时,就会发生该错误.

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.

您必须等到视频播放后才能设置currentTime

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

这篇关于InvalidStateError:尝试使用一个不可用或不再可用的对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-01 19:48