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.