InvalidStateError:尝试使用一个不可用或不再可用的对象 [英] InvalidStateError: An attempt was made to use an object that is not, or is no longer, usable

查看:716
本文介绍了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

InvalidStateError:试图使用一个不是的对象, 或不再可用

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

第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:尝试使用一个不可用或不再可用的对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆