【发布时间】:2016-06-08 15:19:39
【问题描述】:
我需要通过 JS 访问 YouTube 状态来控制视频幻灯片。出于某种原因,我收到 getPlayerState() is not a function 消息。我可以直接访问 playerState 属性,尽管我想按照文档中所述的“正确”方式进行操作。有谁知道这可能是什么问题造成的?
相关代码:
if (window.YTIframeAPIReady) {
ytPlayers[this.id] = new YT.Player(this.id, {
events: {
'onStateChange': youtubeStateChange,
}
}
}
function youtubeStateChange(event) {
// This returns the player state.
console.log(event.target.v.playerState);
// This returns Uncaught TypeError: event.target.getPlayerState is not a function
console.log(event.target.getPlayerState());
}
我在网站的另一部分有类似的代码,似乎仍在使用getPlayerState(),所以我有点难过。非常感谢任何帮助,
【问题讨论】:
-
请尝试这篇 SO 帖子中给出的解决方案 - Youtube iframe player JS API with jQuery - player object has no method 'getPlayerState'。我希望这也涵盖了您的问题。
-
@Teyam
this.id是框架的 ID。
标签: javascript jquery youtube-api