Setup web audio api source node from soundcloud

自作多情 提交于 2019-11-28 20:38:32

问题


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:


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



来源:https://stackoverflow.com/questions/13455956/setup-web-audio-api-source-node-from-soundcloud

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!