8

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

xavier.seignard
  • 11,254
  • 13
  • 51
  • 75

1 Answers1

13

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

Misha Reyzlin
  • 13,736
  • 4
  • 54
  • 63