Multiple Sounds
by Paul Leech
HTML
<div>
<a width="10px" height="10px" type="button" value="PLAY" onclick="play_F('https://www.freesound.org/data/previews/366/366328_6039328-lq.mp3')">Press</a>
<a width="10px" height="10px" type="button" value="PLAY" onclick="playChord('A3','C4','E4')">ACE</a>
</div>
CSS
body > div > a {
margin: 20px;
}
body > div > a:hover {
cursor: pointer;
}
JavaScript
function note(file){
var audio = document.createElement('audio');
audio.src = `https://js.netcentrx.net/_media/${file}.mp3`;
document.body.appendChild(audio);
audio.play();
audio.onended = function () {
this.parentNode.removeChild(this);
}
}
function playChord(array) {
array.forEach(item => {
console.log('item = ' + item);
note(item);
});
}