function playMusic(){
var music = new Audio('musicfile.mp3');
if (music.paused) {
music.play();
} else {
music.pause();
}
}
<input type="button" value="sound" onclick="playMusic()" />
When I click on the sound button, it plays the music. However, if I click on it again, it plays the music twice. I am searching for a solution to enable playing and pausing the music with one button press. Thank you.