Skip to content

Commit 5aac3be

Browse files
Nikhil GiridharanNikhil Giridharan
authored andcommitted
Splash: default sound on, tap splash to unlock if autoplay blocked
Made-with: Cursor
1 parent 9c1c61f commit 5aac3be

1 file changed

Lines changed: 22 additions & 6 deletions

File tree

src/api/static/index.html

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@
734734
<source src="/static/splash-intro-fallback.mp3" type="audio/mpeg">
735735
</audio>
736736

737-
<button type="button" id="tp-audio-toggle" aria-pressed="false" aria-label="Turn sound on" title="Sound off — click for retro trading-floor jazz"
737+
<button type="button" id="tp-audio-toggle" aria-pressed="true" aria-label="Turn sound off" title="Sound on — click to mute retro jazz"
738738
style="
739739
position: absolute;
740740
bottom: 46px;
@@ -760,10 +760,10 @@
760760
<span id="tp-audio-toggle-icon" aria-hidden="true" style="display:flex;width:20px;height:20px;align-items:center;justify-content:center;">
761761
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
762762
<path d="M11 5L6 9H2v6h4l5 4V5z" stroke="currentColor" stroke-width="2" stroke-linejoin="round"/>
763-
<path d="M23 9l-6 6M17 9l6 6" stroke="currentColor" stroke-width="2" stroke-linecap="round"/>
763+
<path d="M15.54 8.46a5 5 0 010 7.07M19.07 4.93a9 9 0 010 14.14" stroke="currentColor" stroke-width="2" stroke-linecap="round"/>
764764
</svg>
765765
</span>
766-
<span id="tp-audio-toggle-label">Sound off</span>
766+
<span id="tp-audio-toggle-label">Sound on</span>
767767
</button>
768768

769769
<div style="
@@ -996,7 +996,7 @@
996996
var on = !introMusic.paused;
997997
audioToggleBtn.setAttribute('aria-pressed', on ? 'true' : 'false');
998998
audioToggleBtn.setAttribute('aria-label', on ? 'Turn sound off' : 'Turn sound on');
999-
audioToggleBtn.title = on ? 'Sound on — retro jazz (click to mute)' : 'Sound off — click for retro trading-floor jazz';
999+
audioToggleBtn.title = on ? 'Sound on — retro jazz (click to mute)' : 'Tap anywhere or click for retro jazz';
10001000
if (audioToggleLabel) audioToggleLabel.textContent = on ? 'Sound on' : 'Sound off';
10011001
if (audioToggleIcon) {
10021002
audioToggleIcon.innerHTML = on
@@ -1040,14 +1040,30 @@
10401040
});
10411041
}
10421042

1043-
syncIntroAudioButton();
1043+
// Default sound on: first tap/click anywhere on splash starts playback if autoplay was blocked (mute button excluded)
1044+
var splashAudioRoot = document.getElementById('tp-splash');
1045+
if (splashAudioRoot && introMusic && !audioLoadFailed) {
1046+
var splashAudioUnlock = function(ev) {
1047+
if (audioLoadFailed || dismissed) return;
1048+
if (ev.target.closest && ev.target.closest('#tp-audio-toggle')) return;
1049+
if (!splashAudioRoot.contains(ev.target)) return;
1050+
introMusic.play().then(function() {
1051+
splashAudioRoot.removeEventListener('pointerdown', splashAudioUnlock, true);
1052+
syncIntroAudioButton();
1053+
}).catch(function() {});
1054+
};
1055+
splashAudioRoot.addEventListener('pointerdown', splashAudioUnlock, true);
1056+
}
10441057

1045-
// Try autoplay where allowed (Chrome may still block until gesture — toggle always works)
10461058
if (introMusic && !audioLoadFailed) {
10471059
var introPlayTry = introMusic.play();
10481060
if (introPlayTry !== undefined) {
10491061
introPlayTry.then(function() { syncIntroAudioButton(); }).catch(function() { syncIntroAudioButton(); });
1062+
} else {
1063+
syncIntroAudioButton();
10501064
}
1065+
} else {
1066+
syncIntroAudioButton();
10511067
}
10521068

10531069
function dismiss() {

0 commit comments

Comments
 (0)