alexa-samples/skill-sample-nodejs-audio-player

Using JSON to populate audioData?

Closed this issue · 4 comments

Hi, I'm trying to use JSON to populate the audioData in audioAssets, but I can't seem to get it to work.

I'm using the request module, with this code

var request = require('request');

var episodes = [];
var titles = [];

request.get('http://mywebsite/json.asp', function (error, response, body) {
	if(error) {
		console.log(error);
	}
    if (!error && response.statusCode == 200) {
        var podcasts = JSON.parse(body);

	    for(var i = 0; i < podcasts.length; i++) {
            episodes[i] = podcasts[i].episode_mp3.toString();
	titles[i] = podcasts[i].podcast_name.toString() + ' Episode ' + podcasts[i].episode_number.toString() + ' ' + podcasts[i].episode_title.toString();
          }
		
    }
	
});

I can run this code in the index file and console.log episodes[i] and titles[i] and it outputs all the correct information. Any reason this wouldn't work within the audioAssest file? I think it's an issue with timing, but I'm not sure how to fix it.

Hi @ryandeming ,
everything ok now?
Where was the mistake?

Sure like to know what the solution was coz I'm running into the same problem, with no solution for the moment

any news please i need it

To be honest, I don't remember. It had something to do with async functions if I recall correctly. Maybe try using a promise?