How to use the Youtube API?

0

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?

    
asked by anonymous 27.05.2016 / 17:40

1 answer

1

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);
    
27.05.2016 / 23:08