Shoutcast + Web Audio API CORS

I have a problem that I have been working on for some time, without real progress. I am currently trying to load a Shoutcast stream into my Web Audio API context. I figured that would violate CORS, and I was right. I tried both through the XHR request, and through loading the audio element in the script. He worked with an audio element, but died while trying to load it into a script. It seems my only option is to try somehow to add the CORS headers to the stream that my Shoutcast is serving.

I have no idea how to do this, and have no luck finding resources on the Internet. If anyone can give me some advice on this, it will be very appreciated!

var audioCtx = new (window.AudioContext || window.webkitAudioContext)(); var soundSource, concertHallBuffer; ajaxRequest = new XMLHttpRequest(); ajaxRequest.open('GET', 'http://127.0.0.1:8000/;stream.mp3', true); ajaxRequest.responseType = 'arraybuffer'; ajaxRequest.onload = function() { var audioData = ajaxRequest.response; console.log(audioData); audioCtx.decodeAudioData(audioData, function(buffer) { concertHallBuffer = buffer; soundSource = audioCtx.createBufferSource(); soundSource.buffer = concertHallBuffer; soundSource.connect(audioCtx.destination); soundSource.loop = true; soundSource.start(); }, function(e){"Error with decoding audio data" + e.err}); } ajaxRequest.send(); 
+5
source share
1 answer

Just to answer my own question. I was able to get this working with the shoutcast stream by setting up a reverse proxy in apache, which pointed to my stream and scream port.

+2
source

All Articles