Note: This is a knowledge-sharing question because I've already found a nice solution.
The problem:
The playlist implementation (http://jplayer.org/latest/demo-02-jPlayerPlaylist/) was built by utilising the jPlayer events. One of the side effects of this is that if you want to respond to track start by binding to 'setmedia', and track end by binding to the 'ended' event, you will find that 'ended' is triggered only after the next line was activated.
This means that the events will fire in this order:
- setmedia of track #1
- setmedia of track #2 (including moving the jp-playlist-current class)
- ended of track #1
So the question is: how to get the 'ended' event be fired before moving to the next track?