Skip to content Skip to sidebar Skip to footer

"cannot Call Method 'oembed' Of Null" When Embedding Soundcloud Player In Dynamically Generated Div

Using the Soundcloud JavaScript API, I want to dynamically generate a page of player widgets using track search results. My code is as follows:

Solution 1:

Solved it. I took out the SC argument from the callback function and makeDivsFromTracks(), and now all the players show up. Not sure exactly why this works--maybe it has to do with the SC object being defined in the SDK script reference, so it's globally available and doesn't need to be passed into functions?

Anyways, working code is:

<html><head><scriptsrc="http://connect.soundcloud.com/sdk.js"></script><script>functionmakeDivsFromTracks(tracks)
{
 var track;
 var permUrl;
 var newDiv;
 for(var ctr=0;ctr<tracks.length;ctr++)
 {
  newDiv=document.createElement("div");
  newDiv.id="track"+ctr;
  track=tracks[ctr];
  //newDiv.innerHTML=track.permalink_url;SC.oEmbed(track.permalink_url,{color:"ff0066"},newDiv);
  document.body.appendChild(newDiv);

 }
}
</script></head><body><script>SC.initialize({
    client_id: 'MY_CLIENT_ID'
});
SC.get('/tracks',{duration:{from:180000,to:900000},tags:'hitech',downloadable:true},function

(tracks){makeDivsFromTracks(tracks);});
</script></body></html>

Post a Comment for ""cannot Call Method 'oembed' Of Null" When Embedding Soundcloud Player In Dynamically Generated Div"