benji1123 / www.benli99.xyz

https://www.benli99.xyz/
http://www.benli99.xyz/
0 stars 0 forks source link

can't decode audio buffer on prod, but works on local #23

Open benji1123 opened 1 year ago

benji1123 commented 1 year ago

Throws this error on prod when audioCtx.decodeAudioData(buf) is executed No erorr in localhost

Uncaught (in promise) DOMException: Failed to execute 'decodeAudioData' on 'BaseAudioContext': Unable to decode audio data
Promise.then (async)
getSongFromAPI @ source.js:36
toggleMusic @ source.js:47
onclick @ (index):27
audioCtx = new (window.AudioContext || window.webkitAudioContext)();
    playSound = audioCtx.createBufferSource()
    // TODO: get this song from API instead of local storage
    const song_1980_dont_stop = '../media/audio/heart-change-brock-hewitt-stories-in-sound-main-version-04-28-13106.mp3'
    fetch(song_1980_dont_stop)
        .then(data => data.arrayBuffer())
        .then(buf => audioCtx.decodeAudioData(buf)) // error here
        .then(decodedAudio => {
            playSound.buffer = decodedAudio;
            playSound.connect(audioCtx.destination);
            playSound.start(audioCtx.currentTime);
            console.log(audioCtx);
        });