5
我有一個問題,我一直在努力一段時間,沒有真正的進展。我目前正試圖將我的Shoutcast流加載到我的Web Audio API上下文中。我想它會違反CORS,我是對的。我嘗試通過XHR請求,然後再通過將音頻元素加載到腳本中。它與音頻元素一起工作,但在嘗試將其加載到腳本時死亡。看來我唯一的選擇是嘗試以某種方式將CORS頭添加到Shoutcast服務的流中。Shoutcast + Web Audio API CORS問題
我不知道如何做到這一點,並沒有運氣在線尋找資源。如果有人可以給我一些建議,這將非常感謝!
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();
可能的重複:http://stackoverflow.com/questions/30603872/how-can-i-avoid-cors-restriction-for-web-audio-api –