diff --git a/index.html b/index.html index 8233ff9..6a666c4 100644 --- a/index.html +++ b/index.html @@ -23,9 +23,7 @@ diff --git a/script.js b/script.js index 2c138d0..35f0d4d 100644 --- a/script.js +++ b/script.js @@ -1,27 +1,31 @@ const audioFiles = { - rain: new Audio('audio/rain.mp3'), - fire: new Audio('audio/fire.mp3'), + rain: [new Audio('audio/rain.mp3'), 'Rain.wav by inchadney | License: Attribution 4.0'], + fire: [new Audio('audio/fire.mp3'), 'Fire Four.wav by CountryRoadFilms | License: Attribution 3.0'], }; for (const audio in audioFiles) { - audioFiles[audio].loop = true; + audioFiles[audio][0].loop = true; const soundControl = document.createElement('div'); soundControl.classList.add('sound'); soundControl.innerHTML = ``; document.getElementById('sound-controls').appendChild(soundControl); + + const attribution = document.createElement('li'); + attribution.innerHTML = `${audio.charAt(0).toUpperCase() + audio.slice(1)} sound: ` + audioFiles[audio][1]; + document.getElementById('audio-attribution-list').appendChild(attribution); } function toggleSound() { if (!playing) { for (const audio in audioFiles) { - audioFiles[audio].play(); + audioFiles[audio][0].play(); playing = true; } } else { for (const audio in audioFiles) { - audioFiles[audio].pause(); + audioFiles[audio][0].pause(); playing = false; } } @@ -31,12 +35,16 @@ document.getElementById('toggle').addEventListener('click', toggleSound); const sliders = document.getElementsByClassName('sound-slider'); +function updateVolumes() { + for (const audio in audioFiles) { + const slider = document.getElementById(audio + '-slider'); + audioFiles[audio][0].volume = slider.value / 100; + } +}; + Array.from(sliders).forEach(slider => { slider.addEventListener('input', function (e) { - for (const audio in audioFiles) { - const slider = document.getElementById(audio + '-slider'); - audioFiles[audio].volume = slider.value / 100; - } + updateVolumes(); }) }); @@ -60,4 +68,6 @@ document.addEventListener('DOMContentLoaded', () => { }); }); -var playing = false; \ No newline at end of file +var playing = false; + +updateVolumes(); \ No newline at end of file