I am trying to access soundcloud audio with the web audio API. I am using the below audio element to get the audio (and picking up from javascript with createMediaElementSource)
<audio id='stream' src="" crossorigin='anonymous'></audio>
But this produces a CORS error, even though Soundcloud is meant to support CORS
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at .128.mp3?Policy=eyJTdGF0ZW1lbnQiOlt7IlJlc291cmNlIjoiKjovL2NmLW1lZGlhLnNuZGNkbi5jb20vT2ZqTVpvMjdEbHZILjEyOC5tcDMiLCJDb25kaXRpb24iOnsiRGF0ZUxlc3NUaGFuIjp7IkFXUzpFcG9jaFRpbWUiOjE0MzU0MTI0NzR9fX1dfQ__&Signature=SwXVan2GT2pvaP2Db5VtpElWKcUNVJdEd1MVsvjWu1NLNyt~BPMJO2Yx1Z1vvbX3hc887sw4BabAQBqlp6UldpxK13kizR2l2PJsnMRrO9Tm-MgaoWWDNr0QdUDJeqOp8do94lriA72IwYg21dm61-onQFpuKTZGR7wlvLeiQWMWJArEC0ATj7XfAM-Dy4bCrKGMHFhd6PbkcNigkS00~oUMes~HfjYzph~tAB~EAFcjqx4LFyBM6qMWb63O1U3~-jG39YFOHfR5-VqqA7ojEugtaAlJ30eUp3ygmG9jmfUHoaq1ebU1fIWsx94KOzDEY-8psqLhrj5LjWMBLf5kLg__&Key-Pair-Id=APKAJAGZ7VMH2PFPW6UQ. This can be fixed by moving the resource to the same domain or enabling CORS.
Is this the correct way to access soundcloud clips from web audio api? If not what's the best way to do it?
Thanks in advance
I am trying to access soundcloud audio with the web audio API. I am using the below audio element to get the audio (and picking up from javascript with createMediaElementSource)
<audio id='stream' src="http://api.soundcloud./tracks/204082098/stream?client_id=MYCLIENTID" crossorigin='anonymous'></audio>
But this produces a CORS error, even though Soundcloud is meant to support CORS
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://cf-media.sndcdn./OfjMZo27DlvH.128.mp3?Policy=eyJTdGF0ZW1lbnQiOlt7IlJlc291cmNlIjoiKjovL2NmLW1lZGlhLnNuZGNkbi5jb20vT2ZqTVpvMjdEbHZILjEyOC5tcDMiLCJDb25kaXRpb24iOnsiRGF0ZUxlc3NUaGFuIjp7IkFXUzpFcG9jaFRpbWUiOjE0MzU0MTI0NzR9fX1dfQ__&Signature=SwXVan2GT2pvaP2Db5VtpElWKcUNVJdEd1MVsvjWu1NLNyt~BPMJO2Yx1Z1vvbX3hc887sw4BabAQBqlp6UldpxK13kizR2l2PJsnMRrO9Tm-MgaoWWDNr0QdUDJeqOp8do94lriA72IwYg21dm61-onQFpuKTZGR7wlvLeiQWMWJArEC0ATj7XfAM-Dy4bCrKGMHFhd6PbkcNigkS00~oUMes~HfjYzph~tAB~EAFcjqx4LFyBM6qMWb63O1U3~-jG39YFOHfR5-VqqA7ojEugtaAlJ30eUp3ygmG9jmfUHoaq1ebU1fIWsx94KOzDEY-8psqLhrj5LjWMBLf5kLg__&Key-Pair-Id=APKAJAGZ7VMH2PFPW6UQ. This can be fixed by moving the resource to the same domain or enabling CORS.
Is this the correct way to access soundcloud clips from web audio api? If not what's the best way to do it?
Thanks in advance
Share Improve this question asked Jun 27, 2015 at 13:39 SlidonSlidon 4132 gold badges5 silver badges16 bronze badges 2- There's an SDK available, and documentation – adeneo Commented Jun 27, 2015 at 13:45
- Yes, an example is given on how to play the audio but I am unsure as how to link it up with web audio – Slidon Commented Jun 27, 2015 at 14:32
2 Answers
Reset to default 7You can do it that way:
var audio = new Audio();
audio.src = 'http://api.soundcloud./tracks/204082098/stream?client_id=17a992358db64d99e492326797fff3e8';
audio.controls = true;
audio.autoplay = true;
audio.crossOrigin = "anonymous";
document.body.appendChild(audio);
var context = new (window.AudioContext || window.webkitAudioContext)();
window.addEventListener('load', function(e) {
var source = context.createMediaElementSource(audio);
source.connect(context.destination);
}, false);
https://jsfiddle/iambnz/t6Ln0424/
I think you might be running into the same thing another poster did a while back ago. Please check my answer at SoundCloud Api redirect confusion and Audio Api Streams
tl;dr - Soundcloud seems to have disabled CORS for certain tracks, but not all. The one in your example is served from cf-media.sndcdn. which doesn't provide the CORS headers needed.