YouTube Javascript API onstateChange 事件问题
我的 javascript:
function onYouTubePlayerReady()
{
playerObj = document.getElementById("player_embed");
playerObj.addEventListener("onStateChange", test);
// Make sure the document is loaded before any DOM-manipulation
$(document).ready(function() {
// Update player information every 500ms
setInterval(updatePlayerInfo, 500);
});
}
function test(newState)
{
alert(newState);
}
我的视频已正确加载,我可以通过我的 javascript 对其进行精细控制。然而 onStateChange 事件似乎永远不会触发。当我播放/停止/暂停视频等时,它永远不会发出警报。有人有解决方案/类似问题吗?
My javascript:
function onYouTubePlayerReady()
{
playerObj = document.getElementById("player_embed");
playerObj.addEventListener("onStateChange", test);
// Make sure the document is loaded before any DOM-manipulation
$(document).ready(function() {
// Update player information every 500ms
setInterval(updatePlayerInfo, 500);
});
}
function test(newState)
{
alert(newState);
}
My videos are loaded correctly and I can control fine them through my javascript. However the onStateChange event never seems to trigger. It never comes up with an alert when I'm playing/stopping/pausing videos etc. Anyone with a solution/similar problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您必须将函数名称作为字符串传递给
addEventListener
。You must pass the function name as a string to
addEventListener
.这种格式适用于 JQuery,但逻辑是相同的,在 onYouTubePlayerReady 中创建一个函数来传递playerId
This format is for JQuery but the logic is same, create a function inside onYouTubePlayerReady to pass the playerId