Order Now AdSolution Sign Up | Login » Bits on the Run Sign Up | Login »

Forums

/

reloading playlist after state = completed

7 replies [Last post]

Hi,

I've been struggling with reloading the playlist (asp page returning random xml playlist). When the state is completed and currentitem = num of songs in playlist, I have it doing:

player.sendEvent('LOAD', flashvars);

I've tried everything I can think of .... the player loads the new playlist, but not item 0, it starts playing the same playlist.index as was playing before the reload.

I have tried adding:

player.sendEvent('ITEM', 0);

AND IT PLAYS ITEM 1 ??????? For some reason I can't get it to play item 0 .....

Has anyone ran into this, or know how I can fix it?

Let me know what you want to see codewise....

oops, a quick setTimeout on the 'ITEM' call fixed it :)

I'm having the same problem, and I'd like to avoid using a timeout to 'fix' it. Perhaps a callback from the LOAD function might be useful. Anyone know if something like this exists already?

I have yet to find any alternative to using setTimeout after getting a handle on the jw player object. Also, here is a write-up on my experience using the flv jw player: http://ossolab.com/articles/2009/02/15/playing-nicely-with-the-jw-video-player

 
Those who don't know what they are doing shouldn't be writing articles about it; they just look like fools!

A very reliable way of checking to see if the JW FLV Media Player is ready, so you can add Listeners or start using the API, is to check for the availability of the playlist.

This technique and the code for utilizing it has been posted on these Forums many times by myself and others.

This technique is nothing new; Googling for JavaScript "time delay" or similar terms will find many pages showing this time delay looping technique.

The complete code (this particular code is ultimately for redirecting when an item has finished playing, however it could be any use of the API):

    <script type="text/javascript">
      var player       =  null;
      var currentItem  =  null;

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

      function addListeners()
      {
        if(player.getPlaylist())
        {
          player.addModelListener('STATE',      'stateMonitor');
          player.addControllerListener('ITEM',  'itemMonitor');
        }
        else
        {
          setTimeout("addListeners()", 100);
        }
      };

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

      function stateMonitor(obj)
      {
        if((obj.newstate == "COMPLETED") && ((currentItem + 1) == (player.getPlaylist().length)))
        {
          document.location.href = "http://www.someredirecturl.com";
        }
      };

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

So what you are saying is that playerReady, doesn't mean that the player is ready for addModelListener. I've tracked this through the debugger in both IE and Firefox and you are correct. Unfortunately, the getPlaylist doesn't seem to work either, i.e. addModelListener throws an error also when getPlaylist is not null. I assume that if getPlaylist returns null addModelListener will always return an error.

So what is the best solution here, I would try calling addModelListener anyway, and seeing if it throws an error, even though this is not great programming practice, but in FF, this seems to screw the browser and I need to reboot it.

Does someone have another solution?

getPlaylist should never return null unless you have specifically reprogrammed it to return null. It does return undefined if the player is not fully ready and therefore cannot yet return the playlist object.

I've used this method a lot on IE6/7, FF2/3, and Opera9 and it always works, even when I purposely "borked" the playlist so it wouldn't load properly.

EDIT: The v4.4.162 returns null. I guess it's been a while since I checked that.

Anyway, still seems to work just fine in FF2/3 when attempting to load a "borked" playlist.
 

that's not what I was referring to. I'm not really interested during playerready in the playlist, I want to be able to set addmodelListener without causing an error.

What is the best way to do that during playerready?

m