You actually need to bind to the source tag for listening to error event when willing to detect "file not found error". Have a look at this fiddle.
HTML:
<p id="player1">Non existent audio files - click to play</p>
<audio preload="none" controls>
<source id="wav" src="http://example.com/non-existant.wav" />
<source id="mp3" src="http://example.com/non-existant.mp3" />
<source id="ogg" src="http://example.com/non-existant.ogg" />
</audio>
Script:
$("#player1").on("click", function () {
//I've tried catching the error like this - no effect
alert("Trying to play file.");
try {
$('audio')[0].play();
} catch (e) {
alert("Error playing file!");
}
});
$("audio").on("error", function (e) {
alert("Error at audio tag level!");
});
// try this then
$("#wav").on("error", function (e) {
alert("Error with wav file!");
});
$("#mp3").on("error", function (e) {
alert("Error with mp3 file!");
});
$("#ogg").on("error", function (e) {
alert("Error with ogg file!");
});
It is described in this MDN article - section error handling. Let me know if it works for you.