A few years ago I was researching a topic for playing sound in a game, and SoundManager is an easier way to play audio using JavaScript.
First way:
If you go to the documentation, you will see that SoundManager intercepts clicks on MP3 links and plays them inline . The script assigns additional CSS classes to links to indicate their status (play / pause, etc.)
<a href="/mp3/foo.mp3" title="Play sound" class="sm2_button">Play Link</a>
Check out the demo and more info.
Second way
If you want to use personalized buttons instead of links or images or any other html element, you can use the onClick event to play / pause the sound, for example:
Sound Download:
<script> soundManager.onready(function() { soundManager.createSound({id:'mySound1',url:'/audio/foo.mp3'}); " }); </script>
Buttons:
<button id="play" onclick="soundManager.play('mySound1');return false">Play Button</button> <button id="pause" onclick="soundManager.pause('mySound1');return false">Pause Button</button>
You can find more information about the API.
source share