swfobject 事件监听器不工作?

发布于 2024-12-12 13:28:24 字数 566 浏览 2 评论 0原文

我基本上从 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

長街聽風 2024-12-19 13:28:24

引用 YT API 参考:

注意:要测试任何这些调用,您的文件必须在网络服务器上运行,因为 Flash 播放器限制本地文件和互联网之间的调用。

To quote the YT API reference:

Note: To test any of these calls, you must have your file running on a webserver, as the Flash player restricts calls between local files and the internet.

眼波传意 2024-12-19 13:28:24

检查你的“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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文