2

I'm using the Youtube video iframe API and everything works perfect. There's only one thing left for it to work as i spected: I want to detect when the video focus is out, even if it happends in the same window or browser tab, for it to stop playing, or pause.

i have been trying with jquery:

function onPlayerStateChange(event) {
    if (event.data == YT.PlayerState.PLAYING) {
        player.blur(function(){
            $(this).stopVideo();
        });
    }
}

But it doesn't seems to work. Can somebody help?

1 Answers1

1

Try attaching an on method as such:

$('#parentElement').on('focusout', '.playerSelector', function() { //DO STUFF// });
Araymer
  • 1,315
  • 1
  • 10
  • 16