alternative source not working since version 4.2.6

Author: almeidazCreated Apr 24, 2025Updated Jun 28, 2025
xml
<audio controls id="audio">
      <source
        src="https://www.mywebsite.com/source1.mp3"
      />
      <source
         src="https://www.mywebsite.com/source2.mp3"
      />
</audio>

in medialement-and-player.js

javascript
node.addEventListener('error', function (e) {
			if (e && e.target && e.target.error && e.target.error.code === 4 && isActive) {
				if (index < total && mediaFiles[index + 1] !== undefined) {
					node.src = mediaFiles[index++].src;
					node.load();
					node.play();
				} else {
					mediaElement.generateError('Media error: Format(s) not supported or source(s) not found', mediaFiles);
				}
			}
		});

I was able to fix it by replacing

javascript
if (index < total && mediaFiles[index + 1] !== undefined) {

by

javascript
if (index < total)  {

Source: mediaelement/mediaelement