Play .mp3 if .wav file is not found

I have some audio assets combined with mp3 and wav file. I have an application that loops through the data name and just combine it with the extension and get the source of the audio based on the name like the code below. My problem is that it only get the .wav file.

setTimeout( () => { = '../assets/audio/'+this.type+'/'+voice+'.wav';

      if (! { = '../assets/audio/'+this.type+'/'+voice+'.mp3';
    }, 400);

What will I do to play the .mp3 if the .wav is not found?

Currently my code is not working.

you have to load the file and test if its not there, not testing if your path value is empty - which it never is, cause you defined it above.

You currently do:

if (!('../assets/audio/'+this.type+'/'+voice+'.wav'))

Hi, right now, I’m loading my audio directly by setting the source. But I’m not really sure how to load the file first and test. Can you help me some idea on what you mean? thank you.

use any file plugin to test on wether the loading works to find out if the file exists. When your lucky you may find a plug-in with which you can test if it exists directly.

You did something which can’t work ever, its basically the same as:

var aString = "hello world";
// this will never run