Reputation: 1980
I'm facing with the jwplayer api and I want to get some events, but I will have more than one player in my page, so when I get an event, I need to know which player is firing the event.
Something like the youtube api does:
function onPlayerReady(event) {
n = event.target.id - 1; //The index of the player which fire the event
}
But in jwplayer I don't know how to do:
//PARA TODOS LOS REPRODUCTORES
for (var i = 0; i < videos.length; i++) {
var id = videos[i];
jwplayer(id).setup({
file: "http://content.bitsontherun.com/videos/lWMJeVvV-364767.mp4",
events: {
onReady: function(ev) {
alert('ha iniciado el reproductor '+INDEX OF THE PLAYER WHICH FIRE THE EVENT);
},
onComplete: function(ev) {
alert('ha finalizando el reproductor '+INDEX OF THE PLAYER WHICH FIRE THE EVENT);
}
}
});
}
Upvotes: 1
Views: 1322
Reputation: 4201
When using our API - http://www.longtailvideo.com/support/jw-player/28851/javascript-api-reference
You can target specific players.
For example, jwplayer() will be the first player on a page, but you can also do jwplayer('my-player'), to target a player called 'my-player', for example. You don't need to set the events in the events block either, you can set them up in outside scripts.
Upvotes: 0
Reputation: 1980
You can save whatever you want this way:
for (var i = 0; i < videos.length; i++) {
var id = videos[i];
jwplayer(id).setup({
file: "http://content.bitsontherun.com/videos/lWMJeVvV-364767.mp4",
my_var: videos[i], /*WHATEVER YOU WANT AS A VARIABLE OF THE PLAYER*/
events: {
onReady: function(ev) {
alert('ha iniciado el reproductor '+this.config.my_var);
},
onComplete: function(ev) {
alert('ha finalizando el reproductor '+this.config.my_var);
}
}
});
}
Upvotes: 1