Reputation:
I am using bootstrap slider on my page. I need to pause the currently playing video when slider moves to the next one. I tried using youtube callback but it doesnt seems like working, may be my way of applying is not right.
here is what I have used
jQuery(function ($) {
$('div.carousel-inner div.active').attr('id', 'current');
});
function callPlayer(frame_id, func, args='') {
if (window.jQuery && frame_id instanceof jQuery) frame_id = frame_id.get(0).id;
var iframe = document.getElementById(frame_id);
if (iframe && iframe.tagName.toUpperCase() != 'IFRAME') {
iframe = iframe.getElementsByTagName('iframe')[0];
}
if (iframe) {
iframe.contentWindow.postMessage(JSON.stringify({
"event": "command",
"func": func,
"args": args || [],
"id": frame_id
}), "*");
}
jQuery(function ($) {
$('div.carousel-inner div.item').attr('id', '');
$('div.carousel-inner div.active').attr('id', 'current');
});
}
Upvotes: 2
Views: 5716
Reputation: 2785
I modified your HTML as follows.
- onclick="callPlayer("current","pauseVideo")"
+ onclick="callPlayer('current','pauseVideo')"
And I change LOAD TYPE from onLoad
to No wrap in <head>
.
However, You should attach Click Event with jQuery on
method.
Upvotes: 1
Reputation: 384
You could use the youtube iframe api. For that you have to append ?enablejsapi
to your iframe source. You should maybe follow the tutorial from youtube.
https://developers.google.com/youtube/iframe_api_reference
Also answered in this question: Pausing YouTube iFrame API in JavaScript
Upvotes: 0