【发布时间】:2015-10-14 17:42:02
【问题描述】:
我有这个嵌入了一些简洁小工具的自定义 YouTube,它运行良好,但有一个问题。控制台有很多错误如:
Uncaught TypeError: Cannot read property 'getVolume' of undefined
index.html:189 Uncaught TypeError: player.getVolume is not a function
index.html:179 Uncaught TypeError: player.getCurrentTime is not a function
index.html:183 Uncaught TypeError: player.getCurrentTime is not a function
我不知道是什么导致了这些错误,我已经尝试用代码做很多事情,例如移动和重新分配变量,但我似乎无法清除它们,有什么帮助吗?
【问题讨论】:
-
Cannot read property 'getVolume' of undefined表示player在 js 第 83 行未定义。其余部分也是如此,player内部没有函数,因为它仍然未定义。当您尝试访问它时,变量player可能仍然为空。 -
播放器变量不能为空,视频正在加载...所以这意味着它已被启动。我正在加载播放器下方的所有其他变量
-
由于您在
onYouTubeIframeAPIReady()函数内为player变量赋值,所以当setInterval()函数被触发时,player is still undefined(js 第 72 和 81 行)。在将播放器创建到player变量后,您必须启动(或调用)间隔到onYouTubeIframeAPIReady()。 -
好的!我让“未定义”错误消失了,但是现在我如何让“不是函数”错误消失?因为它显然在工作......我似乎无法确定为什么我的代码没有将“getVolume”和“getCurrentTime”识别为函数,而它们显然正在工作
标签: jquery html css youtube-api