0

I am facing a weird issue where I am able to play audio if I run my app on localhost but after deployment, audio doesn't play. I am using HTMLAudioElement to play the audio. Below is what I am trying to do:

    const ringtone = new Audio('/src/assets/audio/ringtone.mp3');
    ringtone.load();
    ringtone.preload = 'auto';
    ringtone.crossOrigin = 'anonymous';
    ringtone.currentTime = 0;
    ringtone.play();

Not sure what am I missing here. The console shows below error on Chrome:

Uncaught (in promise) DOMException: Failed to load because no supported source was found.

As per other answers, it could be because of CORS issue or audio file is not available. But I have already set crossOrigin to anonymous and audio file is part of assets directory where other logo and images are placed and app is able to pick those images.

Edit: It is not duplicate as it is not a CORS issue as pointed in other answers. I have already set crossOrigin setting to anonymous and also my audio file resides within assets directory and not being streamed from elsewhere.

justcurious
  • 254
  • 3
  • 15
  • Possible duplicate of [DOMException: Failed to load because no supported source was found](https://stackoverflow.com/questions/37674223/domexception-failed-to-load-because-no-supported-source-was-found) – Igor Alemasow Sep 07 '18 at 09:51
  • @IgorAlemasow Well, I already went through the link but mine is not a CORS issue as I already mentioned it in details. I have already taken care of CORS setting. – justcurious Sep 07 '18 at 09:55

0 Answers0