Here is the code:
var holder;
var findSong;
var embedHolder;
$(".hypemList ol").on('click','li',function (){
holder = $(this).text();
findSong = SC.get('/tracks', { q: holder });
embedHolder = findSong._result[0].uri;
SC.oEmbed(embedHolder // song to embed
, { color: "ff0066"
, auto_play: false
, maxwidth: 500
, maxheight: 1000
, show_comments: true // options
, element: document.getElementById("soundTest") // what element to attach player to
});
});
What I would like to happen:
I have a list of songs that I would like to play. When I click on the song, I will grab that string and then search soundcloud API
using that string. I will take index 0 of the result and place that in SC.oEmbed
to play the song.
When I open dev console, I get this error when I click on a song --
Uncaught TypeError: Cannot read property '_result' of undefined.
I believe I need to wait for findSong
to finish and then I can use embedHolder
and place that into SC.oEmbed
.
What I have done:
I found this: returning array from function in javascript. I tried following what they did, but it didn't seem to work.
I'd appreciate it if someone could point me in the right direction on what to do next.