JSFiddle - React, Tailwind, and code Playground
by phated
JavaScript
var audio = new Audio();
var sounds = [
{ type: 'audio/mpeg', filename: 'epic-theme.mp3' },
{ type: 'audio/webm', filename: 'epic-theme.webm' }
];
audio.addEventListener('error', function(){
sounds = sounds.filter(function(sound){
return audio.src.indexOf(sound.filename) < 0;
});
sounds.some(function(sound){
return audio.canPlayType(sound.type)
&& (audio.src = sound.filename);
});
});
sounds.some(function(sound){
return audio.canPlayType(sound.type) && (audio.src = sound.filename);
});