BTEC IT Unit 20 - Website Design/JavaScript/Button - Play/Stop Music
Appearance
Play/Stop music using an image
<a onclick="myAudioFunction('A');" ondblclick="myAudioFunctionStop('A');">
<img src="music.jpg" style="width:100px">
</a>
<script>
var aAudio = new Audio('music.mp3');
function myAudioFunction(letter) {
if(letter == 'A') {
aAudio.play();
}
}
function myAudioFunctionStop(letter) {
if(letter == 'A') {
aAudio.pause();
}
}
</script>