How to use Soundcloud api to get stream into html5 audio player?

后端 未结 2 1210
孤街浪徒
孤街浪徒 2021-02-02 04:11

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

2条回答
  •  庸人自扰
    2021-02-02 04:37

    At a cursory glance, it looks like all soundcloud API objects come with a URI property that links directly to the resource. In your case, it would be sound.uri.

    At the top of your player code, you have an tag - my guess is you'll want to set it's src to the URI value for the track you're playing. You can do this by attaching an ID to it and calling

    SC.stream("/tracks/293", function(sound){
        $("[audio_id]").attr("src", sound.uri);
    });
    

    replacing [audio_id] with whatever ID you choose for the tag. You'll probably still have to do something to reinitialize/restart the player each time it changes, but that will hopefully get you started. Let me know how it works!

提交回复
热议问题