YouTube的API - 停止视频 [英] Youtube api - stop video

查看:300
本文介绍了YouTube的API - 停止视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一些帮助与YouTube API和嵌入式视频。
我想一些元素(DIV,链接,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>

在此先感谢任何建议。

thanks in advance for any advices

推荐答案

如果您使用的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>

您code的其余部分应后,其通常工作,尽管它可能需要被更新,以说:

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>

此外,你看过演示站点? <一href=\"http://$c$c.google.com/apis/youtube/youtube_player_demo.html\">http://$c$c.google.com/apis/youtube/youtube_player_demo.html

这篇关于YouTube的API - 停止视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆