Last active
July 26, 2017 17:51
-
-
Save mendes5/534351abb5cc7dc9cb3f776ced06f2d0 to your computer and use it in GitHub Desktop.
Play a track from soundcloud, good for webaudio experiments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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