fixed a bug in music player
Marco Andronaco andronacomarco@gmail.com
Mon, 19 Sep 2022 02:51:06 +0200
4 files changed,
20 insertions(+),
14 deletions(-)
M
index.html
→
index.html
@@ -67,12 +67,17 @@ </div>
<div id="music-player" onmouseenter="showTitle()" onmouseleave="hideTitle()" style="bottom: -100%"> <div id="music-player-base" onclick="playPause()"> <div id="music-player-overlay"></div> - <audio controls loop id="music"><source id="music-source" src="#"></audio> + <audio loop id="music"><source id="music-source" src="#"></audio> </div> <div id="music-player-song" style="top: 100%;"> <span id="song-text">Jay Tholen - Awesome Rap Beat (Hypnospace Outlaw Original Soundtrack, Vol. 2)</span> </div> </div> + <audio id="loadelement1"><source src="res/sfx/os/loadelement1.ogg"></audio> + <audio id="loadelement2"><source src="res/sfx/os/loadelement2.ogg"></audio> + <audio id="loadelement3"><source src="res/sfx/os/loadelement3.ogg"></audio> + <audio id="loadelement4"><source src="res/sfx/os/loadelement4.ogg"></audio> + <script src="res/slow_load.js"></script> <script src="res/script.js"></script> </body>
M
res/iframe.js
→
res/iframe.js
@@ -1,5 +1,2 @@
- -const this_page = document.body.getAttribute("data-page"); - hide_all(); -parent.loadIFrame(() => parent.frameLoadedCallback(this_page));+parent.loadIFrame(parent.frameLoadedCallback);
M
res/script.js
→
res/script.js
@@ -94,9 +94,9 @@ element.onmousedown = () => playAudio(click1);
element.onmouseup = () => playAudio(click2); } -function frameLoadedCallback(page) { +function frameLoadedCallback() { controlsEnabled = true; - playPause(!play, page_tracks[page]); + playPause(!play, page_tracks[currentPage]); } function goToPage(page) {@@ -106,6 +106,7 @@ music.pause()
controlsEnabled = false; iframe.src = "pages/" + page + ".html"; currentPage = page; + } function formatTrack(track) {@@ -131,6 +132,13 @@ music_song.style.top = "100%";
} function playPause(toggle=play, track=currentTrack) { + let changed = false; + if (track != currentTrack) { + changed = true; + currentTrack = track; + source.src = "res/mus/" + tracks[currentTrack].file_name; + music.load(); + } if (!controlsEnabled) return;@@ -142,13 +150,9 @@ hideTitle();
} else { music_base.classList.add("player-play"); - if (track != currentTrack) { - currentTrack = track; - source.src = "res/mus/" + tracks[currentTrack].file_name; - music.load(); - } music.play().catch(() => {}); - showTitle(); + if(changed) + showTitle(); play = true } }
M
res/slow_load.js
→
res/slow_load.js
@@ -14,7 +14,7 @@
function playAudio(audio){ audio.volume = 0.1; audio.currentTime = 0; - audio.play(); + audio.play().catch(()=>{}); } const all = document.getElementsByTagName("*");