/    Sign up×
Community /Pin to ProfileBookmark

JPlayer(JQuery) playlist array problem

Hi, JPlayer supports playlists, but it keeps the playlist in the javascript:

[CODE] var myPlayList = [
{name:”Tempered Song”,mp3:”http://www.miaowmusic.com/mp3/Miaow-01-Tempered-song.mp3″},
{name:”Hidden”,mp3:”http://www.miaowmusic.com/mp3/Miaow-02-Hidden.mp3″},
{name:”Lentement”,mp3:”http://www.miaowmusic.com/mp3/Miaow-03-Lentement.mp3″},
{name:”Lismore”,mp3:”http://www.miaowmusic.com/mp3/Miaow-04-Lismore.mp3″,ogg:”http://www.miaowmusic.com/ogg/Miaow-04-Lismore.ogg”},
{name:”The Separation”,mp3:”http://www.miaowmusic.com/mp3/Miaow-05-The-separation.mp3″,ogg:”http://www.miaowmusic.com/ogg/Miaow-05-The-separation.ogg”},
{name:”Beside Me”,mp3:”http://www.miaowmusic.com/mp3/Miaow-06-Beside-me.mp3″,ogg:”http://www.miaowmusic.com/ogg/Miaow-06-Beside-me.ogg”},
{name:”Bubble”,mp3:”http://www.miaowmusic.com/mp3/Miaow-07-Bubble.mp3″,ogg:”http://www.miaowmusic.com/ogg/Miaow-07-Bubble.ogg”},
{name:”Stirring of a Fool”,mp3:”http://www.miaowmusic.com/mp3/Miaow-08-Stirring-of-a-fool.mp3″,ogg:”http://www.miaowmusic.com/ogg/Miaow-08-Stirring-of-a-fool.ogg”},
{name:”Partir”,mp3:”http://www.miaowmusic.com/mp3/Miaow-09-Partir.mp3″,ogg:”http://www.miaowmusic.com/ogg/Miaow-09-Partir.ogg”},
{name:”Thin Ice”,mp3:”http://www.miaowmusic.com/mp3/Miaow-10-Thin-ice.mp3″,ogg:”http://www.miaowmusic.com/ogg/Miaow-10-Thin-ice.ogg”}
];[/CODE]

I’m trying to read in an xml file into this “myPlayList” array so that I can have an easy way of updating it, but I’m having trouble understanding this array structure.

In the JPlayer code they use “myPlayList[i].name” and “myPlayList[i].mp3″ in a for loop to cycle through the playlist and display the links in a list.

My idea was to get rid of the “myPlayList” var declaration and dynamically populate the array variable from my xml file:

[CODE] var xmlDoc;
var myPlayList = []
if (window.XMLHttpRequest)
{
xmlDoc=new window.XMLHttpRequest();
xmlDoc.open(“GET”,”playlist.xml”,false);
xmlDoc.send(“”);
xmlDoc=xmlDoc.responseXML;
}
// IE 5 and IE 6
else if (ActiveXObject(“Microsoft.XMLDOM”))
{
xmlDoc=new ActiveXObject(“Microsoft.XMLDOM”);
xmlDoc.async=false;
xmlDoc.load(“playlist.xml”);
}
x=xmlDoc.getElementsByTagName(“track”);
for (i=0;i<x.length;i++)
{
myPlayList[i].name = x[i].childNodes[0].nodeName;
myPlayList[i].mp3 = x[i].childNodes[1].nodeName;
}[/CODE]

It didn’t display any songs ?

I’m not sure what I’m doing wrong. Please help. Also, I’m guessing this has been done before (although I did a google search and couldn’t find anything), so If you could point me to some resources I’d appreciate it. If there is another simpler option (over xml) I’d like to know.

Thanks.

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@andersoneeauthorJul 06.2009 — I'm guessing no one is replying because there's two paragraphs of code and no one really wants to read through it. If you're just glancing at it, it looks like alot but it's actually fairly small and straitforward when you look at what it's doing.

Please, could someone have a look. I think this is probably a fairly common problem so I'm guessing it'll be easy for some of you.


thanks
×

Success!

Help @andersonee spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...