I have a page with a video that opens in a modal, needs to be paused when the modal is hidden. I tested examples I found on other sites but it did not work.
Do I need to add any extra files to use the API control?
I have a page with a video that opens in a modal, needs to be paused when the modal is hidden. I tested examples I found on other sites but it did not work.
Do I need to add any extra files to use the API control?
I do not know how you are closing your modal, but if you are using .hide()
of jQuery, you can do the following:
function pause_video(){
$('#youtube_iframe_id')[0].contentWindow.postMessage('{"event":"command","func":"pauseVideo","args":""}', '*');
}
function hideCallBack() {
pause_video()
}
With the two functions added in your code, your video will be paused when you close the modal using:
$('#modal_id').hide(hideCallBack);