Play playlist or track by permalink not trackid
I have an embedded player that works by trackId but:
For both these reasons it is inconvenient that the player needs trackId. Is there a way I can play off the permalink?
Thanks, Martin.
PS. My current iframe code looks like this:
src="https://w.soundcloud.com/player/?url=http%3A%2F%2Fapi.soundcloud.com%2Fplaylists%2F$paramPlaylistID"
This iFrame code (from Comment #1) doesn't work:
src="https://w.soundcloud.com/player/?url=http://api.soundcloud.com/resolve.json?url=http%3A%2F%2Fapi.soundcloud.com%2Fplaylists%2F$paramPermalink"
Is there something better I can use? I recognize that I may need to do something to the url=...url= but I'm not clear whether resolve works with this player or whether the answer only applies to if I'd made a custom player.
Thanks again, M.
See SoundCloud's API docs on resolve
:
The resolve resource allows you to lookup and access API resources when you only know the SoundCloud.com URL.
$ curl -v 'http://api.soundcloud.com/resolve.json?url=http://soundcloud.com/matas/hobnotropic&client_id=YOUR_CLIENT_ID'
< HTTP/1.1 302 Moved Temporarily
< Location: http://api.soundcloud.com/tracks/49931.json
This request will resolve and redirect to the API resource URL for the track http://soundcloud.com/matas/hobnotropic. Just follow the redirect and you will get the representation you want. The resolver supports URLs for:
You can take a the permalink from a user and get the track or playlist ID like so:
function getSoundCloudId(permalink, callback) {
var resolve = 'http://api.soundcloud.com/resolve.json?client_id=YOUR_CLIENT_ID&url=';
var request = new XMLHttpRequest();
request.onreadystatechange = function(){
if (this.readyState === 4 && this.responseText) {
var response = JSON.parse(this.responseText);
if (response.id) callback(response.id);
}
};
request.open('get', resolve+permalink, true);
request.send();
}
Then you use it like so:
getSoundCloudId('https://soundcloud.com/matas/sets/library-project', function(id){
// Do stuff with the ID
console.log(id);
})
链接地址: http://www.djcxy.com/p/65300.html
上一篇: Soundcloud嵌入流URL(Node,JSON)
下一篇: 播放播放列表或按固定链接跟踪未跟踪