-1

I am trying to retrieve songs from soundcloud api and use the oembed to play the songs like so:

        var url = 'https://api.soundcloud.com/tracks.json?client_id=ddddea95338821004a98791d999c1118&q=park&filter=all&order=created_at';
        $.getJSON(url, function(tracks){
            var random = Math.floor(Math.random() * 49 );
            SC.oEmbed(tracks[random].uri, {autoplay: true}, document.getElementById('wrap'));

            console.log(tracks[random].title);
            console.log(tracks[random].id);
        });

apparently soundcloud returns a list of 50 tracks and i want to get a random track from that list, but i get the NS_ERROR_DOM_BAD_URI: Access to restricted URI denied error on line 1 of sdk.js, which is weird because I can retrieve the id and the title of the song into the console log, what am I doing wrong?

jgillich
  • 71,459
  • 6
  • 57
  • 85
user2209644
  • 701
  • 1
  • 9
  • 21

1 Answers1

1

Use the permalink_url, not the uri - from tracks object.

SC.oEmbed(tracks[random].permalink_url, document.getElementById("wrap"));

http://jsfiddle.net/iambnz/cAspQ/

hwsw
  • 2,596
  • 1
  • 15
  • 19