0

Looking at previous answer I became with the idea of retrying to play sound:

soundBG.pause();
soundBG.currentTime = 0;
var soundPromise = soundBG.play();

if (soundPromise !== undefined) {
    soundPromise.then(function() {
        console.log('Sound!');
    }).catch(function(error) {
        console.error('Failed to start your sound, retrying.');
        setTimeout(function(){
            soundEffects();
        }, 2000);
    });
}

but its still not working and when the sound is not working I keep getting the error:

DOMException: Failed to load because no supported source was found

is there anyway to solve that?

Community
  • 1
  • 1
Sandra
  • 315
  • 3
  • 16

1 Answers1

-1

I had the same error with an Audio type file and used it

var url = document.querySelector('audio').src;
var audio = new Audio();
audio.src = url;
var playPromise = audio.play();
if (playPromise !== undefined) {
      playPromise.then(function() {
         audio.addEventListener('timeupdate',function() {
            console.log(audio.currentTime, audio.duration);
         }, true);
      }).catch(function(error) {
            console.error('Failed to start your sound, retrying.');
      });
}
Israt Jahan Simu
  • 1,040
  • 13
  • 7