Forum Discussion
the order of the audios in the dom tree is not fixed
it can be different at every start
test with firefox, first start
second start
=> different order
so your methode to find the correct audio cannot work
idea: identify the filenames of the audio
var filename1 = audioElement1.src.split("/").slice(-1)
var filename2 = audioElement2.src.split("/").slice(-1)
var filename3 = audioElement3.src.split("/").slice(-1)
var filename4 = audioElement4.src.split("/").slice(-1)
so you can use the filenames to find the correct audio
It's working fine now. I made this adjustment to go by file name instead of dom order:
// Find audio elements based on filenames
var audioElement1 = findAudioElement("audio1.mp3");
var audioElement2 = findAudioElement("audio2.mp3"); // Just an example of file name
var audioElement3 = findAudioElement("6D6r7VdJ4SD_44100_160_0.mp3"); // This is more how the file names looks after publishing
var audioElement4 = findAudioElement("6b4wCyNNRLl_44100_160_0.mp3");
// Find audio element based on filename
function findAudioElement(filename) {
var audioElements = document.querySelectorAll('audio');
for (var i = 0; i < audioElements.length; i++) {
var src = audioElements[i].src;
if (src.includes(filename)) {
return audioElements[i];
}
}
return null; // If filename is not found
}
This way it is working perfect, in any browser.
Thanks Jürgen!
@Sam Hill, thanks for your input.