Playing mp3 file results in NotSupportedError

I’m trying to play a file using NUI, but when I try to play it this error pops up in the client console:

script:nlalert:nui Uncaught (in promise) NotSupportedError: The element has no supported sources. (@nlalert/html/script.js:5)

This is my script.js:

var audioFile = new Audio('nlalert.mp3');

function playAlertSound() {
    audioFile.volume = 0.2;
    audioFile.play();
}

function disableAlertSound() {
    audioFile.pause();
    audioFile.currentTime = 0;
}

$(function() {
    window.addEventListener('message', function(event) {
        switch (event.data.action) {
            case 'enable':
                $('body').show();
                playAlertSound();
            break;

            case 'disable':
                $('body').hide();
                disableAlertSound();
            break;

            default:
            break;
        }
    });
});

I hope someone is able to help me out!

mp3 is a commercial codec, try using something like Vorbis (.ogg) instead.

1 Like