Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setup web audio api source node from soundcloud

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

like image 408
xavier.seignard Avatar asked Nov 19 '12 14:11

xavier.seignard


People also ask

Does SoundCloud have API?

To access the SoundCloud® API, you will first need to register your app at https://soundcloud.com/you/apps using your SoundCloud® account. When you've done that, we'll issue you with a client ID and client secret. Your client ID is required for all calls to the SoundCloud® API.

What protocol does SoundCloud use?

Our primary protocol is HLS (HTTP Live Streaming). This means the contents of a track are split up into short segments, and we have a separate file (playlist), which contains URLs to all of the segments, along with their corresponding times in the track.

Does SoundCloud use JavaScript?

The SDKs will make it easier to access the SoundCloud API on your framework of choice. We officially provide and support only JavaScript. All other SDKs (Ruby, Python) are supported by third-party developers.


1 Answers

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

like image 124
Misha Reyzlin Avatar answered Oct 20 '22 22:10

Misha Reyzlin