如何在嵌入式SoundCloud播放器上添加搜索


How could I add a search on an embed SoundCloud player?

我正在为我的网站编写一个SoundCloud播放器。我想知道我是否可以使用这里预览的SoundCloud API搜索歌曲。

请分享任何其他参考资料或样品。

为您提供的Soundcloud API端点:

http://developers.soundcloud.com/docs/api/reference#tracks

如果你在这里创建了一个小小提琴来演示如何使用SC JS SDK。

http://jsfiddle.net/iambnz/2AMen/

 SC.initialize({
    client_id: "201b55a1a1xxxxxxxxxxxxxxxxxx",
  //  redirect_uri: "http://example.com/callback.html",
  });
SC.get("/tracks", {limit: 10, genres: "jazz"}, function(tracks){
        var length = tracks.length;
        for (var i = 0; i < length; i++){
            $('#results').append(tracks[i].genre + ' | ' + tracks[i].permalink_url + '<br/>');
    }
}); 

您的示例看起来是使用php后端实现的。

这就是适合您的SDK:

https://github.com/mptre/php-soundcloud

这是一个使用这个SDK的php示例:

   <?php
include 'Services/Soundcloud.php';
$soundcloud = new Services_Soundcloud('yourClientId', 'yourClientSecret', 'yourRedirectUri');
try {
    $tracks = json_decode($soundcloud->get('tracks', array('genres' => 'jazz', 'limit' => '10')));
} catch (Services_Soundcloud_Invalid_Http_Response_Code_Exception $e) {
    exit($e->getMessage());
}
print_r($tracks);
?>