2

Possible Duplicate:
How can I stop a video with Javascript in Youtube?

I was wondering how I can use Twitter Bootstrap's modal feature to autoplay a Youtube video and when a user clicks the "close" button, it will stop the video from playing.

I have tried adding the following to my application.js file without prevail.

$('#my-video').on('hide', function () {
  player.stopVideo();
})

HTML view

<div class="modal hide" id="myModal">
  <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
  <div class="modal-body">
    <iframe width="560" height="315" src="http://www.youtube.com/embed/30Pjl31cyDY?rel=0" frameborder="0" allowfullscreen></iframe>
  </div>
</div>

Any insights is much appreciated.

4

1 回答 1

0
player.stopVideo(); 

仅当player是您通过 Youtube API 创建的 YT.player 对象时才有效。您可以在此处了解如何通过 javascript 控制 youtube 播放器: https ://developers.google.com/youtube/iframe_api_reference

于 2012-09-15T09:30:23.913 回答