diff --git a/img/forest_river.mp3 b/audio/forest_river.mp3 similarity index 100% rename from img/forest_river.mp3 rename to audio/forest_river.mp3 diff --git a/audio/orchard_glen.mp3 b/audio/orchard_glen.mp3 new file mode 100644 index 0000000..2297d50 Binary files /dev/null and b/audio/orchard_glen.mp3 differ diff --git a/index.html b/index.html index 62bf0f9..1e86126 100644 --- a/index.html +++ b/index.html @@ -31,12 +31,18 @@
Humble home of user gome -
- +
+ Play a song
+
+ + + + Play another song +

diff --git a/js/gomesong.js b/js/gomesong.js index 26429fe..2678c2b 100644 --- a/js/gomesong.js +++ b/js/gomesong.js @@ -1,11 +1,22 @@ -const gomesong = document.getElementById('gomesong'); -const music_box = document.getElementById('music-box'); -music_box.addEventListener('click', () => { - if (gomesong.paused) { - music_box.classList.add('playing'); - gomesong.play(); - } else { - music_box.classList.remove('playing'); - gomesong.pause(); - } -}); +function get_audio(music_box) { + return music_box.querySelector('audio'); +} + +const music_boxes = document.getElementsByClassName('music-box'); +for (const music_box of music_boxes) { + music_box.addEventListener('click', () => { + const audio = get_audio(music_box); + if (audio.paused) { + // pause all other music boxes + for (const music_box of music_boxes) { + music_box.classList.remove('playing'); + get_audio(music_box).pause(); + } + music_box.classList.add('playing'); + audio.play(); + } else { + music_box.classList.remove('playing'); + audio.pause(); + } + }); +}