Go
Not registered? Sign up!

PLAYLIST event not firing

Google Translate
5 posts | return to the Bug Reports forum | get the rss feed for this thread

Oct. 09, 2009Stephen

Hi there,

I'm having real problems getting the PLAYLIST event to fire consistently in version 4.5.230 using the JavaScript API. IT seems to fire in Firefox but not other browsers (I have tested IE and Safari). Here's a snippet of the code I'm using to test this:


function playerReady(obj) {

var id = obj['id'];
player = document.getElementById(id);

player.addControllerListener('PLAYLIST','playlistListener');
player.addControllerListener('ITEM','itemListener');

}

function playlistListener(obj) {
alert("playlist");
}

function itemListener(obj) {
alert("item");
}


The ITEM stuff is my control group and seems to work just fine.

Thanks,
Stephen

Oct. 09, 2009lost

 
You need to add Listeners like this:
    <script type="text/javascript">
      var player       =  null;
      var playlist     =  null;
      var currentItem  =  null;


      function playerReady(obj)
      {
        player = gid(obj.id);
        addListeners();
      };


      function addListeners()
      {
        playlist = player.getPlaylist();

        if((playlist !== null) && (playlist.length > 0))
        {
          player.addControllerListener('ITEM', 'itemMonitor');
        }
        else
        {
alert('Try Again!');
          setTimeout("addListeners();", 100);
        }
      };


      function itemMonitor(obj)
      {
        currentItem = obj.index;
      };


      function gid(name)
      {
        return document.getElementById(name);
      };
    </script>


Here's why:

In the JW FLV Player, in ActionScript3, the call to load the playlist is an asynchronous event (meaning it goes off on it's own, lolly-gagging around, and loads the playlist when it damn well pleases).

Until the player has loaded and parsed the playlist, you can't do anything.

So the code above tries to get the playlist through the JavaScript API and if not successful, tries again in 100ms. Once the playlist has been successfully retrieved, you can add Listeners and interact with the player.

Why 100ms? Well, t's been my experience, that if you use a 50ms delay, you will almost always see the alert; if you use 100ms, you will seldom see the alert.

Of course, remove the alert once you are done playing around and use whatever Listeners and other events you need. The itemMonitor is just there for illustrative purposes.

Oct. 12, 2009Stephen

Thanks for your reply, lost.

Until the player has loaded and parsed the playlist, you can't do anything.

But that is the reason for having a PLAYLIST event listener in the JavaScript api?

In the JW FLV Player, in ActionScript3, the call to load the playlist is an asynchronous event (meaning it goes off on it's own, lolly-gagging around, and loads the playlist when it damn well pleases).

So am I correct to infer that the playlist is loaded before (or alongside) the JavaScript event listeners being bound? The playlist is processed and the event fired before the listener has been attached?

Your code above creates a manual listener for the playlist by polling it's status, which, while it works, is a workaround for a documented API feature no longer working properly. It would be more elegant to handle this with an event listener as per previous versions of the player and in that sense this seems a regression bug.

Many thanks,
Stephen

Oct. 21, 2009Stephen

Hello again. I was just wondering if there is any thoughts on this? I have written two jQuery plugins that wrap the functionality of the player and rely on this event. Both work reliably with versions 4.2 and 4.3.

I am wondering whether I now need to make these plugins work around this issue (complicating them somewhat) or whether this is, as I suspect, a bug. In the latter case any fix would need only apply to the versions it affects or I could skip versions 4.4 and 4.5 altogether.

One of these plugins I would like to release as open source.

Oct. 25, 2009Zachary Ozer

Hi Stephen,

Assuming playerReady has been called, and you're attaching the listener to the player in obj['id'], all should be well.

Are there multiple players on the page?

Add a reaction

You can also return to the category or try this search for related threads.


 

Search the Forums

Go

Support

Support Here are some helpful links to learn more about the JW Player™:

Monetize Your Video

Monetize Your Video Earn money with ads from LongTail's AdSolution. Watch our demos and sign up now!

Why Buy a License?

Why Buy a License? If you don’t buy a commercial license, you cannot use a JW Player™ on (i) a site that has ads; (ii) a corporate site; or a (iii) CMS. Our licenses are very inexpensive, so what are you waiting for? Buy a license today.