I'm working with Bootstrap 3 modals with Youtube video iframes on them. I implemented a simple javascript function to stop the video when the modal is hidden using this piece of js
$('.music-modal').on('hidden.bs.modal', function () {
callPlayer('yt-music', 'stopVideo');
});
And the embeded video looks like
<div class="youtube" data-embed="gjMBua_1J4Y" id="yt-music">
<iframe frameborder="0" allowfullscreen="" src="https://www.youtube.com/embed/gjMBua_1J4Y?rel=0&controls=0&showinfo=0&autoplay=1&enablejsapi=1"></iframe>
</div>
This works seamlessly but only with 1 iframe in 1 modal. I have to do a new js function for every video I add, because the callPlayer function I'm using to send messages to Youtube videos only accepts the iframe id as a parameter.
I want to stop the currently playing video when modal event hidden fires. Is possible to capture that, get the iframe in THAT modal by id, and then stop the video with JS?