javascript - 声云 API : how to use SoundCloud song w/o the embed player?

标签 javascript html web-applications embed soundcloud

根据 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&amp;color=ff5500&amp;auto_play=false&amp;hide_related=false&amp;show_artwork=true&amp;show_comments=true&amp;show_user=true&amp;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)

例子:

最佳答案

扩展@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/

相关文章:

python - 在 Web.py 上进行身份验证 - 此代码对于生产环境是否安全?

javascript - 如何从特定数组中获取新数组

javascript - 自动更改正文字体大小

html - 如何将单元格拆分为列,使它们的宽度与其下方的列相同

html - 如何更改单选按钮 'selected' 状态外观?

java - 许多 Webapp 项目的 JSF Webapp 模板

javascript - 为什么我的 setInterval 函数在我的对象中不起作用?

javascript - 在浏览器窗口中打开新选项卡(使用 window.open 打开)

javascript - 将未定义类型的不受控输入更改为受控

azure - 用于 asp.net core 的 ELMAH