Last Updated: February 25, 2016
·
679
· iYaroslav

JS sound playing in background

function playSound(fName) {
    try {
        if (this.player != undefined) {
            player.pause();
        }

        player = new Audio(fName);
        player.play();
    } catch(v) {
        console.log(v.message);
    }
}