Skip to content

Commit 1e1ea24

Browse files
Nikhil GiridharanNikhil Giridharan
authored andcommitted
Splash: background music with autoplay fallback, stop on dismiss
Made-with: Cursor
1 parent 2232fad commit 1e1ea24

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

src/api/static/index.html

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,10 @@
728728
<div style="position:absolute;bottom:8px;left:24px;width:40px;height:40px;border-bottom:1px solid rgba(0,212,255,0.2);border-left:1px solid rgba(0,212,255,0.2);"></div>
729729
<div style="position:absolute;bottom:8px;right:24px;width:40px;height:40px;border-bottom:1px solid rgba(0,212,255,0.2);border-right:1px solid rgba(0,212,255,0.2);"></div>
730730

731+
<audio id="tp-intro-music" loop preload="auto">
732+
<source src="https://assets.mixkit.co/music/preview/mixkit-tech-house-vibes-130.mp3" type="audio/mpeg">
733+
</audio>
734+
731735
</div>
732736

733737
<style>
@@ -924,10 +928,37 @@
924928
// ── Dismiss logic ─────────────────────────────────────────────
925929
var dismissed = false;
926930

931+
// Autoplay music — browsers require user gesture first
932+
// Attempt autoplay immediately, fall back to playing on first interaction
933+
var music = document.getElementById('tp-intro-music');
934+
if (music) {
935+
music.volume = 0.18;
936+
var playPromise = music.play();
937+
if (playPromise !== undefined) {
938+
playPromise.catch(function() {
939+
// Autoplay blocked — play on first mousemove or touch
940+
var startOnInteraction = function() {
941+
music.play();
942+
document.removeEventListener('mousemove', startOnInteraction);
943+
document.removeEventListener('touchstart', startOnInteraction);
944+
};
945+
document.addEventListener('mousemove', startOnInteraction);
946+
document.addEventListener('touchstart', startOnInteraction);
947+
});
948+
}
949+
}
950+
927951
function dismiss() {
928952
if (dismissed) return;
929953
dismissed = true;
930954

955+
// Stop and reset music when splash closes
956+
var music = document.getElementById('tp-intro-music');
957+
if (music) {
958+
music.pause();
959+
music.currentTime = 0;
960+
}
961+
931962
clearTimeout(typeTimer);
932963
if (typeof animFrame !== 'undefined' && animFrame) cancelAnimationFrame(animFrame);
933964

0 commit comments

Comments
 (0)