2012-04-27 212 views
0

我已經嵌入你管視頻停止iframe的YouTube視頻

<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"> 

我怎樣才能阻止這個VID與Javacript?

+0

可能重複[YouTube API取得 - 停止視頻](http://stackoverflow.com/questions/6671232/youtube-api-stop-video ) – 2012-04-27 08:33:57

+0

這些都不適合我,stopVideo()方法無效! – LeBlaireau 2012-04-27 10:35:03

回答

1

最後我不得不使用api來嵌入,所以我參考了vid。 (XXXX是視頻的YouTube編號的)的

<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(); 

    }