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.

Community
  • 1
  • 1
Wasabi Developer
  • 3,523
  • 6
  • 36
  • 60

1 Answers1

0
player.stopVideo(); 

will only work if player is a YT.player object that you have created via the Youtube API. You can learn how to control the youtube player via javascript here: https://developers.google.com/youtube/iframe_api_reference

DaveR
  • 2,355
  • 1
  • 19
  • 36