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
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.