亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

CORS 策略已阻止從來源“null”訪問音頻:請求的資源上不存在

CORS 策略已阻止從來源“null”訪問音頻:請求的資源上不存在

慕容森 2023-04-27 17:04:21
我正在嘗試制作帶有歌曲可視化工具的音樂播放器。我所有的歌曲都在谷歌驅動器上。為了制作可視化工具,我使用了這段代碼。window.addEventListener('load', () => {    canvas = document.getElementById("cnv1");    context = canvas.getContext("2d");    audioctx = new AudioContext();    WIDTH = window.innerWidth - 50;    canvas.width = WIDTH - 50;    HEIGHT = 500;    canvas.height = 500;    analyser = audioctx.createAnalyser();    analyser.fftSize = SAMPLES;    oscillator = audioctx.createOscillator();    oscillator.connect(audioctx.destination);    source = audioctx.createMediaElementSource(music);    source.connect(analyser);    source.connect(audioctx.destination);    freqArr = new Uint8Array(analyser.frequencyBinCount);    barHeight = HEIGHT;    window.requestAnimationFrame(draw);});function draw() {    if (!music.paused) {        bigBars = 0;        r = 0;        g = 0;        b = 255;        x = 0;        context.clearRect(0, 0, WIDTH, HEIGHT);        analyser.getByteFrequencyData(freqArr);        for (var i = 0; i < INTERVAL; i++) {            if (barHeight >= (240)) {                bigBars++;            }            let num = i;            barHeight = ((freqArr[num] - 128) * 3) + 2;            if (barHeight <= 1) {                barHeight = 2;            }            r = r + 10;            if (r > 255) {                r = 255;            }            g = g + 1;            if (g > 255) {                g = 255;            }當我嘗試運行此代碼時,出現此錯誤:CORS 策略已阻止從來源“null”訪問“https://docs.google.com/uc?export=download&id=1Ifx_11yZ-FDdrO5XXseaDiipMBRZjpuB”中的音頻:不存在“Access-Control-Allow-Origin”標頭在請求的資源上。我在音頻標簽中使用了crossorigin="anonymous",我也在<header name = "Access-Control-Allow-Origin" value = "*"> head 中使用了那么為什么我會收到這個錯誤?請幫我。我在互聯網上找不到任何解決方案。
查看完整描述

1 回答

?
鳳凰求蠱

TA貢獻1825條經驗 獲得超4個贊

這是一個 CORS 錯誤。該錯誤提到請求資源的來源docs.google.comnull。

您可能正在從本地文件系統(即 file:///....)上的文件運行此代碼。首先將其托管在 Web 服務器上,然后重試。


查看完整回答
反對 回復 2023-04-27
  • 1 回答
  • 0 關注
  • 217 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號