Skip to content

Instantly share code, notes, and snippets.

@mendes5
Last active July 26, 2017 17:51
Show Gist options
  • Select an option

  • Save mendes5/534351abb5cc7dc9cb3f776ced06f2d0 to your computer and use it in GitHub Desktop.

Select an option

Save mendes5/534351abb5cc7dc9cb3f776ced06f2d0 to your computer and use it in GitHub Desktop.
Play a track from soundcloud, good for webaudio experiments
const playFromSoundCloud = async function (url) {
const uri = encodeURIComponent(url)
const link = `https://api.soundcloud.com/resolve.json?url=${uri}&client_id=17a992358db64d99e492326797fff3e8`
const response = await fetch(link).then(res => res.json()).then(json => json)
const audio = document.createElement('audio')
audio.crossOrigin = "anonymous"
audio.src = `http://api.soundcloud.com/tracks/${response.id}/stream?client_id=17a992358db64d99e492326797fff3e8`
audio.play()
return audio
}
/*
onload = async function(){
const audio = await playFromSoundCloud('INSERT YOUR URL')
const context = new AudioContext()
const analizer = context.createAnalyser()
const input = context.createMediaElementSource(audio)
input.connect(analyser)
input.connect(context.destination)
const freqData = new Uint8Array(200)
//ON MAIN LOOP: analyser.getByteFrequencyData(freqData);
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment