I am making a game with HTML5 and JavaScript.
How could I play game audio via JavaScript?
This is a quite old question but I want to add some useful info. The topic starter has mentioned that he is "making a game"
. So for everybody who needs audio for game development there is a better choice than just an tag or an
HTMLAudioElement
. I think you should consider the use of the Web Audio API:
While audio on the web no longer requires a plugin, the audio tag brings significant limitations for implementing sophisticated games and interactive applications. The Web Audio API is a high-level JavaScript API for processing and synthesizing audio in web applications. The goal of this API is to include capabilities found in modern game audio engines and some of the mixing, processing, and filtering tasks that are found in modern desktop audio production applications.