Search code examples
javascripthtmlaudiohtml5-audio

play multiple sounds simultaneously in javascript


Is there any way to play 2 audio files simultaneously? I have an audio file that will be played in a loop and while this sound plays, I'm trying to play another sound. I was expecting that both of them will be played simultaneously, but it looks like both sounds are placed in a sequence, that only one sound can be played at a time


Solution

  • You can use the Audio constructor

    const music = new Audio('myPathTo/music.mp3')
    const soundEffects = new Audio('myPathTo/effects.mp3')
    

    and then

    music.play()
    soundEffects.play()