Youtube api - 停止视频 [英] Youtube api - stop video
问题描述
我需要有关 Youtube API 和嵌入视频的帮助.单击某个元素(div、link、td 等)时,我想停止视频.我现在试图让它只为 1 个视频工作,但这个脚本的最终功能应该是停止当前页面上加载的所有视频.我已经通读了 YT API 文档,但我真的是 JS 初学者,所以对我来说仍然很难理解.
I need some help with Youtube API and embeded videos. I want to stop video when clicked on some element (div,link,td etc.). I am trying to get it work just for 1 video now, but the final function of this script should be to stop all videos loaded on current page. I have read thru the YT API documentation but Im really beginner in JS so its still quite hard to understand for me.
<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>
提前感谢您的建议
推荐答案
如果您将其嵌入 iframe,您将无法控制它.您必须使用对象嵌入,如下所示:
You can't control it if you embed it with an iframe. You have to use object embedding, like this:
<object id="ytplayer" style="height: 390px; width: 640px">
<param name="movie" value="http://www.youtube.com/v/8Ax-dAR3ABs?version=3&enablejsapi=1">
<param name="allowScriptAccess" value="always">
<embed id="ytplayer" src="http://www.youtube.com/v/8Ax-dAR3ABs?version=3&enablejsapi=1" type="application/x-shockwave-flash" allowfullscreen="true" allowScriptAccess="always" width="640" height="390">
</object>
您的其余代码在此之后通常应该可以正常工作,尽管可能需要更新以说明:
The rest of your code should generally work after that, although it may need to be updated to say:
<a href="javascript:document.getElementById('ytplayer').stopVideo()">Play</a>
另外,你看过演示网站吗?http://code.google.com/apis/youtube/youtube_player_demo.html
Also, have you seen the demo site? http://code.google.com/apis/youtube/youtube_player_demo.html
这篇关于Youtube api - 停止视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!