I have a game where I need background music playing and when I click a button it should play a sound. It plays the sound but stops the music.
The only way to turn the music back on is to have another event such as a button click. Is there any way to play a sound while the background music continues to play?
This is my code so far.
var a = new Audio("Latin Groove Hype App.mp3");
function init()
{
playBackGroundLoop();
}// in html(<body onload = "init()">)
function playSoundEffect()
{
var playSoundCorrect = new Audio("Correct synth.mp3");
playSoundCorrect.play();
}
function playBackGroundLoop()
{
a.addEventListener('ended', function()
{
this.currentTime = 0;
this.play();//plays music on loop
}, true);
a.play();
}
$(function()
{
$("#playButton").on("click",function()
{
playSoundEffect();
}
});
Thank you