javascript - Stream a specific song using Soundcloud API -
i'm still learning how use apis - has given me trouble. believe code correct, nothing happens when try stream song using simple javascript onclick function.
html:
<head> <script src="https://connect.soundcloud.com/sdk/sdk-3.0.0.js"></script> <script src="good.js"></script> </head> <body> <button onclick="playit()">play adele</button> </body>
javascript:
sc.initialize({ client_id: 'xxxxxxxxxx', }); function playit(){ var sound = sc.stream("/emberwaves/adele-set-fire-to-the-rain-remix", function(sound){ sound.play(); }); }
first, use resolve
endpoint api url track:
http get: https://api.soundcloud.com/resolve.json?url=https://soundcloud.com/emberwaves/adele-set-fire-to-the-rain-remix&client_id=[client_id]
response:
http/1.1 302 found access-control-allow-headers: accept, authorization, content-type, origin access-control-allow-methods: get, put, post, delete access-control-allow-origin: * access-control-expose-headers: date cache-control: no-cache content-type: application/json; charset=utf-8 date: thu, 07 jan 2016 19:54:36 gmt location: https://api.soundcloud.com/tracks/43377447.json?client_id=[client_id] server: am/2 status: 302 found content-length: 128 connection: close {"status":"302 - found","location":"https://api.soundcloud.com/tracks/43377447.json?client_id=[client_id]"}
calling request url, can id
track, 43377447
.
change js point @ tracks
endpoint:
var sound = sc.stream("tracks/43377447", function(sound){ sound.play(); });
Comments
Post a Comment