停止iframe youtube视频

时间:2012-04-27 08:29:50

标签: jquery youtube youtube-api

我有一个嵌入式管视频

<iframe width="490" height="279" src="http://www.youtube.com/embed/X7ab_dVhkWk?version=3&enablejsapi=1" frameborder="0" allowfullscreen></iframe>

嵌入时的html

<embed width="100%" height="100%" id="video-player-flash" type="application/x-shockwave-flash" src="http://s.ytimg.com/yt/swfbin/watch_as3-vflCBBX6J.swf" allowscriptaccess="always" allowfullscreen="true" bgcolor="#000000" flashvars="el=embedded&amp;fexp=904544%2C909703%2C920701&amp;is_html5_mobile_device=false&amp;allow_ratings=1&amp;allow_embed=1&amp;tabsb=1&amp;sendtmp=1&amp;hl=en_US&amp;eurl=http%3A%2F%2Fdev.springcorp.co.uk%2Fhistoricscotland%2Fstirling%2Ffacebook-april2012%2F&amp;iurl=http%3A%2F%2Fi2.ytimg.com%2Fvi%2Fai55pL37saU%2Fhqdefault.jpg&amp;view_count=117&amp;title=Regent%20Arran%20Stirling%20Castle%20TV%20ad%202012&amp;avg_rating=0&amp;video_id=ai55pL37saU&amp;length_seconds=31&amp;iurlmaxres=http%3A%2F%2Fi2.ytimg.com%2Fvi%2Fai55pL37saU%2Fmaxresdefault.jpg&amp;enablejsapi=1&amp;sk=UX8fbMJpKT-VH3IVkWhtN7gCKU1r3TSzC&amp;rel=1&amp;playlist_module=http%3A%2F%2Fs.ytimg.com%2Fyt%2Fswfbin%2Fplaylist_module-vflfGS7wE.swf&amp;iurlsd=http%3A%2F%2Fi2.ytimg.com%2Fvi%2Fai55pL37saU%2Fsddefault.jpg&amp;jsapicallback=ytPlayerOnYouTubePlayerReady&amp;playerapiid=player1&amp;framer=http%3A%2F%2Fdev.springcorp.co.uk%2Fhistoricscotland%2Fstirling%2Ffacebook-april2012%2F">

如何使用Javacript停止此视频?

1 个答案:

答案 0 :(得分:1)

最后我不得不使用api嵌入,所以我参考了视频。 (xxxx是视频的youtube ID)

<div id="player"></div>
<div id="player2"></div>
<div id="player3"></div>

<script>
    //Load player api asynchronously.
    var tag = document.createElement('script');
    tag.src = "http://www.youtube.com/player_api";
    var firstScriptTag = document.getElementsByTagName('script')[0];
    firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
   var done = false;
    var player;
    var player2;
   var player3;
    function onYouTubePlayerAPIReady() {
        player = new YT.Player('player', {
          height: '279',
          width: '490',
          videoId: 'xxxxxxxx',

        });

       player2 = new YT.Player('player2', {
          height: '279',
          width: '490',
          videoId: 'xxxxxxx',

        });

        player3 = new YT.Player('player3', {
          height: '279',
          width: '490',
          videoId: 'xxxxxx',

       });
    }

    function stopVideo() {
    player.stopVideo();

    }