Setup web audio api source node from soundcloud

2019-02-01 08:13发布

I would like to know if there is any way to create a source node ( https://dvcs.w3.org/hg/audio/raw-file/tip/webaudio/specification.html#MediaElementAudioSourceNode) from a soundcloud track.

I'm ok with the web audio API, but new to the soundcloud sdk, as far I understand it relies on soundmanager2. So maybe there is some options from soundmanager2 available?

Regards

1条回答
\"骚年 ilove
2楼-- · 2019-02-01 08:39

You can request a track and then use stream_url property, that you can set as src for the audio element, to be used as MediaSourceNode.

Here's an example code:

var context = new webkitAudioContext(),
    audio = new Audio(),
    source,
    // `stream_url` you'd get from 
    // requesting http://api.soundcloud.com/tracks/6981096.json
    url = 'http://api.soundcloud.com/tracks/6981096/stream' +
          '?client_id=YOUR_CLIENT_ID';

audio.src = url;
source = context.createMediaElementSource(audio);
source.connect(context.destination);
source.mediaElement.play();

Here's the example live: http://jsbin.com/ikixot/1/edit

查看更多
登录 后发表回答