First send your request:
CODE
var request = new URL(); //Create a new URL REquest Object
request.location = "http://"+currentAppData.get('host')+"/List?type=mp3<ype="+ltype+"&index="+index+random_song; //The URL passed into grab the information from
request.info = this;
request.fetchAsync(this._loadandplayList); //ALL NETWORK REQUESTS MUST BE DONE VIA AN ASYNC CALL -> NO EXCEPTIONS
then a function that responds to results - the function you specified in the fetchAsync:
CODE
_loadandplayList: function(request) {
print("got list");
KONtx.utility.LoadingOverlay.off();
if ( request.response == 200 ) //A successful network request will return a response of 200
{
print("got list");
playlist = KONtx.mediaplayer.playlist.get();
KONtx.application.setNetworkRequestFailed(false); //We need to tell the Engine that the Network is Still up
try{
var Feed_XML = XMLDOM.parse( request.result ); //If we get a valid reponse back we need to parse out the XML
var list = Feed_XML.evaluate('xml/mp3s/mp3');
for(var i=0; i<list.length;i++) {
//request.info.config.Listitems.push({name: list.item(i).evaluate('string(name)'), index: list.item(i).evaluate('string(index)')});
print(list.item(i).evaluate('string(index)')+" "+list.item(i).evaluate('string(name)'));
var newentry = new KONtx.media.PlaylistEntry({url: "http://"+currentAppData.get('host')+"/Play?"+list.item(i).evaluate('string(index)')});
newentry.config.title = list.item(i).evaluate('string(name)');
newentry.config.album = list.item(i).evaluate('string(album)');
newentry.config.artist = list.item(i).evaluate('string(artist)');
newentry.config.track = list.item(i).evaluate('string(track)');
playlist.addEntry(newentry);
}
KONtx.mediaplayer.playlist.start();
}
catch(e) {
print('DANGER: We could not parse the XML Feed');
KONtx.application.previousView();
}
}
else
{
KONtx.application.setNetworkRequestFailed(true); //We need to tell the Engine that the Network is Still up
KONtx.application.previousView();
}
},