Skip to content
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

how can i catch an event on playback start ? #60

Open
adam-jones-net opened this issue Dec 5, 2016 · 1 comment
Open

how can i catch an event on playback start ? #60

adam-jones-net opened this issue Dec 5, 2016 · 1 comment

Comments

@adam-jones-net
Copy link

adam-jones-net commented Dec 5, 2016

I've tried using the example code to check the state, ie

var player =jQuery("#myvideodiv").data("ytPlayer").player;
player.addEventListener("onStateChange", function(data){
console.log("Player State Change", data);
});

but the player variable is a null so any reference to this results in a JS error

@coudrak
Copy link

coudrak commented Apr 19, 2017

Need a callback.
Look at this example:

 $('#background-video').YTPlayer({
    fitToBackground: true,
    videoId: 'Fk9EBOOAYiU',
    pauseOnScroll: true,
    callback: function() {
      videoCallbackEvents();
    }
  });

  
  var videoCallbackEvents = function() {
    var player = $('#background-video').data('ytPlayer').player;
  
    player.addEventListener('onStateChange', function(event){
        console.log("Player State Change", event);
        // OnStateChange Data
        if (event.data === 0) {          
            console.log('video ended');
        }
        else if (event.data === 2) {          
          console.log('paused');
        }
    });
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants