Reputation: 155
I'm trying to create a dynamic playlist for JPlayer from XML generated from a .php file. This is the code for the .js file:
$(document).ready(function(){
var cssSelector = { jPlayer: "#jquery_jplayer_1", cssSelectorAncestor: "#jp_container_1" };
var playlist = []; // Empty playlist
var options = { swfPath: "../js", supplied: "ogg, mp3" };
var myPlaylist = new jPlayerPlaylist(cssSelector, playlist, options);
$.get ("xml_audio.php", {}, function (xml) {
$('Track', xml).each (function (i) {
var title = $(this).attr('title');
var track_name = $(this).attr('track_name');
var mp3 = 'audio/' + track_name + '.mp3';
var ogg = 'audio/' + track_name + '.ogg';
var obj = ({title: title, mp3: mp3, ogg:ogg});
alert(obj);
playlist.push (obj);
}); /*end of xml .each loop */
}); /* end of xml .get loop */
}); /**end of document.ready loop */
The XML is outputting correctly, and the variables are being picked up. The problem seems to be in the line of code that starts "var obj =" The alert comes back as [object Object]. Is there a problem with the syntax? Or maybe attr is the problem? The player is loading, but no playlist. Thanks for any help, Cheryl
Upvotes: 0
Views: 2251
Reputation: 155
The code above worked when I changed one line. Instead of:
playlist.push(obj);
I used:
myPlaylist.add(obj);
et voila.
Upvotes: 1