-
Notifications
You must be signed in to change notification settings - Fork 73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Stop video from playing when tab is inactive #8
Comments
Added in version 5.3 |
Hi, Thanks! |
@elalemanyo It's possible, but I'm not sure it's worth the extra conditional to do so. Would you mind sharing your code so I can see what you're doing? Worth mentioning, the reload only happens with iFrames. HTML5 video is paused using the video API. |
I have some youtube iframe and I also have some other iframes. All the time was reloading all of them, when user change the tab, that was really annoying. Also I had a small code to pause youtube videos, using youtube API. var tag = document.createElement('script');
tag.src = 'https://www.youtube.com/iframe_api';
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
var players = {};
window.onYouTubePlayerAPIReady = function() {
$('.tabs-content #videos').controlYTiframes();
$('.tabs-content #videos').on('activeTab', function() {
$.each(players, function(index, val) {
stopVideo(index);
});
});
};
$.fn.controlYTiframes = function() {
$(this).find('iframe').each(function (k, v) {
players[v.id] = new YT.Player(v.id, {
events: {
'onStateChange': onPlayerStateChange
}
});
});
}
function onPlayerStateChange(event) {
if (event.data == YT.PlayerState.PLAYING) {
stopVideo(event.target.a.id);
}
}
function stopVideo(player_id) {
$.each(players, function(index, val) {
if (val.getIframe().id != player_id && val.getPlayerState() == 1) {
val.pauseVideo();
}
});
} Not sure if the code can help someone... it is project specific. I pause the videos from same tab, and I pause all of them when user change tab. |
Looking at this documentation, I think you're right about making this an option. I'll add an option to disable |
Added with v10.1.0 #61 |
No description provided.
The text was updated successfully, but these errors were encountered: