Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jwplayer 6 setup no longer supports event callbacks. how to tell when player is ready if I cannot specify onReady callback within setup?

I am trying to migrate from jw5 to jw6. In jw5, I included event callbacks within the player setup. For example:

var myplayer = jwplayer('container').setup({
  flashplayer:  /my/player.swf',
  height: '100%',
  width: '100%', 
  events: {
    'onReady': function(event) {
       alert ("on ready");
    },
    'onPlay': function(event) {
       alert ("on play");
    },        
  }
});

According to the jw5-to-jw6 migration documentation, it seems I can no longer include event callbacks within the player setup:

Removed: the events configuration block This way of adding event listeners is fully redundant with adding listeners outside the setup, both in terms of features and amount of code required.

If I understand correctly, I am supposed to specify the event callbacks this way:

myplayer.onReady( function(event){
  alert('on ready');
});
myplayer.onPlay( function(event){
  alert('on play');
});

My Question:

It seems to me I need to wait for the myplayer object to be ready, before I can define these myplayer event callbacks. True? How do I know when myplayer is ready, if I cannot specify the onReady event callback within the setup?

like image 230
moondog Avatar asked Dec 19 '12 21:12

moondog


1 Answers

In JWPlayer6 you can add onReady event handler the same way you add others. This works for me:

var playerInstance = jwplayer("myElement").setup({
    file: "test.mp4"
});

playerInstance.onReady(function() {
    console.log('ready');

    playerInstance.onPlay(function() {
        console.log('playing');
    });

    playerInstance.play();
});
like image 137
Inferpse Avatar answered Oct 28 '22 17:10

Inferpse