Skip to content

MediaElementWebAudio CORS requests #2014

Description

@sundayz

Wavesurfer.js version(s): 3.3.3

Browser and operating system version(s): Windows Firefox, Chrome

When using MediaElementWebAudio and providing my own peaks data, the backend doesn't load the mp3 file. Firefox gives the error: The HTMLMediaElement passed to createMediaElementSource has a cross-origin resource, the node will output silence. and Chrome: MediaElementAudioSource outputs zeroes due to CORS access restrictions

My web server is sending the cors headers:
Access-Control-Allow-Origin "*"
Access-Control-Allow-Methods "GET"
Access-Control-Allow-Headers "Content-Type: audio/mpeg"

I tried changing xhr settings in wavesurfer too but it didn't help.

After some googling, every answer seems to tell me to do this:
audioElement.crossOrigin = 'anonymous';

source: https://stackoverflow.com/questions/41069039/cors-request-will-not-work-in-chrome

Would changing createMediaElementSource here https://github.com/katspaugh/wavesurfer.js/blob/master/src/mediaelement-webaudio.js#L56 to allow passing an option param be a good idea?

mediaElement.crossOrigin = params.CrossOrigin || "";

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions