swfobject 事件监听器不工作?
我基本上从 youtube api 教程中获取了代码,立即开始视频播放,并调用状态更改的回调。正在播放,因此我知道 onYouTubePlayerReady
函数正在触发,并且 ytplayer 对象已定义。但是,事件侦听器不起作用。
这是加载 YouTube 播放器时的回调函数:
function onYouTubePlayerReady(playerId) {
ytplayer = document.getElementById("myytplayer");
ytplayer.addEventListener("onStateChange", "onytplayerStateChange");
ytplayer.playVideo();
}
这是事件监听器:
function onytplayerStateChange(newState) {
alert("Player's new state: " + newState);
}
我讨厌没有人回答,后来我用谷歌搜索,结果发现我的堆栈溢出问题是最重要的结果之一。
I have essentially taken the code from the youtube api tutorial, starting the video playback immediately, and invoking a callback for state changes. Playing is working, so I know the onYouTubePlayerReady
function is firing, and the ytplayer object is defined. However, the event listener is not working.
Here is the callback function for when the youtube player is loaded:
function onYouTubePlayerReady(playerId) {
ytplayer = document.getElementById("myytplayer");
ytplayer.addEventListener("onStateChange", "onytplayerStateChange");
ytplayer.playVideo();
}
And here is the event listener:
function onytplayerStateChange(newState) {
alert("Player's new state: " + newState);
}
I hate when no one answers and I google it later, only to find out my stack overflow question is one of the top results.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
引用 YT API 参考:
To quote the YT API reference:
检查你的“myytplayer”你在哪里定义的。我遇到了同样的问题,这是由于 Id 参考错误造成的。再次检查一下。
Check your "myytplayer" where did you define that . I had the same problem , it was due to the wrong reference of an Id . check that again.