【发布时间】:2011-10-04 00:21:31
【问题描述】:
我需要一些有关 Youtube API 和嵌入视频的帮助。 我想在单击某些元素(div、link、td 等)时停止视频。我现在正试图让它只为 1 个视频工作,但这个脚本的最终功能应该是停止当前页面上加载的所有视频。我已经阅读了 YT API 文档,但我真的是 JS 的初学者,所以对我来说仍然很难理解。
<html>
<head>
<script type="text/javascript" src="swfobject.js"></script>
</head>
<body>
<a href="javascript:ytplayer.stopVideo()">Play</a>
<br/>
<iframe id="ytplayer" src="http://www.youtube.com/embed/8Ax-dAR3ABs?rel=0&iv_load_policy=3&showinfo=0&enablejsapi=1&version=3&playerapiid=ytplayer" type="application/x-shockwave-flash" frameborder="0" allowscriptaccess="always"></iframe>
</body>
</html>
提前感谢您的任何建议
【问题讨论】:
-
使用
callPlayer("ytplayer", "stopVideo");使用来自Youtube iframe API: how do I control a iframe player that's already in the HTML? 的小函数。 -
您可以尝试使用这样的事件:$("#ytplayer")[0].contentWindow.postMessage('{"event":"command","func":"stopVideo", "args":""}', '*');
标签: javascript api video youtube