Ask coding questions

← Back to all posts
How do I play multiple sound files at once in JS?
NotMrMan (97)

if i use audio.play(); more than once, it cuts the other audio out. is there a way to fix it?

Comments
hotnewtop
heyitsmarcus (342)

The best, and easiest, way I know of is to use hidden audio elements in the DOM (set their display CSS property to none). Put an id on them (such as audio1 and audio2, etc.), and then you can just call them both at the same time to play them (or as many as you'd like):

document.querySelector('#audio1').play();
document.querySelector('#audio2').play();

And they will play at the same time. You can use the same controls with the audio DOM elements that you can with the JS loaded audio objects, so that you can dynamically pause them, as well! =]