如何使用Soundcloud api将流导入html5音频播放器? [英] How to use Soundcloud api to get stream into html5 audio player?

查看:113
本文介绍了如何使用Soundcloud api将流导入html5音频播放器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始学习javascript,并且第一次尝试创建自定义音频播放器,该播放器使用soundcloud的api作为音乐源.

I've just started learning javascript and as my first attempt I'd like to create custom audio player which uses soundcloud's api as a source for music.

到目前为止,这是我设置的:

So far this is what I got set up:

<!DOCTYPE html>
<html>
<head>



<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="http://connect.soundcloud.com/sdk.js"></script>

<script>
window.onload = function() {
SC.initialize({
  client_id: '10e27db0dacd00954d7160b4c092a6e2' //Demo ID
});

SC.stream("/tracks/75868018", function(sound){
    $("audio-test").attr("src", sound.uri);
});
};
</script>



</head>
<body>

<audio id="audio-test" controls></audio>

</body>
</html>

推荐答案

好,知道了.问题是.stream()-它是要交付由.play()函数部署的预打包播放器.

Ok, got it figured out. The problem was the .stream() - it's meant to deliver a prepackaged player, deployed by the .play() function.

如果改用SC.get(),则实际上将访问轨道的属性,并将其嵌入音频标签中.查看我的代码: http://jsfiddle.net/LpzpK/6/

If you use SC.get() instead, you'll actually access the properties of the track, and be able to embed it in an audio tag. See my code: http://jsfiddle.net/LpzpK/6/

仍然存在问题-曲目被标记为401禁止,因此播放器只能加载".您必须找到一种方法来公开要播放的曲目.

There's still a problem - the tracks are marked as 401 forbidden, so the player is only ever "Loading". You'll have to find a way to make the tracks you want to play public.

这篇关于如何使用Soundcloud api将流导入html5音频播放器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆