【发布时间】:2014-01-01 15:44:38
【问题描述】:
我已经研究了几个小时,但没有成功。基本上我有一个 cms,用户可以在其中放置 soundcloud url,如“https://soundcloud.com/cade-turner/cade-turner-symphony-of-light”,然后页面可以显示嵌入的 iframe。我把 api 文档弄红了一段时间,但找不到任何相关的东西。这篇帖子here 已经谈过了,但我只是不太明白答案,我检查了oEmbed 和oEmbed reference,但找不到合适的例子。谁有更多提示?
编辑: 感谢Jacob的回答,我终于设法通过使用ajax来做到这一点。
var trackUrl = 'THE_URL';
var Client_ID = 'CLIENT_ID';//you have to register in soundcound developer first in order to get this id
$.get(//make an ajax request
'http://api.soundcloud.com/resolve.json?url=' + trackUrl + '&client_id=' + Client_ID,
function (result) {//returns json, we only need id in this case
$(".videowrapper, .exhibitions-image, iframe").replaceWith('<iframe width="100%" height="100%" scrolling="no" frameborder="no" src="https://w.soundcloud.com/player/?url=https%3A//api.soundcloud.com/tracks/' + result.id +'&color=ff6600&auto_play=false&show_artwork=true"></iframe>');//the iframe is copied from soundcloud embed codes
}
);
【问题讨论】:
-
很好的答案!您将如何为曲目或专辑执行此操作?
-
@Operator “为曲目或专辑”是什么意思?我正在做一个轨道。 ajax 是为了得到这个轨道的 id
标签: javascript php soundcloud