根据 SoundCloud API Guide ,我可以在网页或网络应用程序上播放来自 SoundCloud 的声音,无需使用嵌入式播放器(下面的示例代码):
<iframe width="100%" height="166" scrolling="no" frameborder="no" src="https://w.soundcloud.com/player/?url=https%3A//api.soundcloud.com/tracks/136405212&color=ff5500&auto_play=false&hide_related=false&show_artwork=true&show_comments=true&show_user=true&show_reposts=false"></iframe>
我想在没有这个嵌入的情况下尝试播放 SoundCloud Assets ;相反,我想了解如何:
- 使用 HTML5 音频播放器播放歌曲
- 播放一首歌曲没有任何音频播放器(即“播放这首歌曲
onLoad
”)
在此方面的任何帮助,包括可以使用 JavaScript 和/或 jQuery 的任何帮助,我们将不胜感激。
原文:
Yep, you can also play sounds from your application. Depending on your needs, you can embed a player widget, use the JavaScript SDK to stream audio content in the browser, or feed a stream url into your own audio player. You can also use our Widget API to control the player and handle events. (from http://developers.soundcloud.com/docs/api/guide#playing)
例子:
- 尝试 JSFiddle:http://jsfiddle.net/mnbishop017/PbhCC/
最佳答案
扩展@Marco 的回答:
var xhr = new XMLHttpRequest(),
stream = new Audio(),
client_id = '?client_id=d4ab52d80ed2e7790c3a243495b30093';
xhr.open('GET', 'http://api.soundcloud.com/tracks/136405212.json' + client_id);
xhr.onload = function(){
var track = JSON.parse(xhr.responseText);
stream.src = track.stream_url + client_id;
stream.play();
};
xhr.send();
关于javascript - 声云 API : how to use SoundCloud song w/o the embed player?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24375668/