diff --git a/src/lib/components/app/bottom-bar.svelte b/src/lib/components/app/bottom-bar.svelte index 92e33f8..c990a5d 100644 --- a/src/lib/components/app/bottom-bar.svelte +++ b/src/lib/components/app/bottom-bar.svelte @@ -2,6 +2,6 @@ import MusicPlayer from "@/components/app/now-playing.svelte"; -
+
\ No newline at end of file diff --git a/src/lib/components/app/daemon.svelte b/src/lib/components/app/daemon.svelte index 7ed97e4..7d27a12 100644 --- a/src/lib/components/app/daemon.svelte +++ b/src/lib/components/app/daemon.svelte @@ -6,6 +6,35 @@ // svelte-ignore non_reactive_update let audioElement: HTMLAudioElement; + // Create a shared function to toggle playback + function togglePlayback(play: boolean) { + if (!audioElement) return; + + if (play && state.hasInteracted) { + audioElement.play().catch(() => { + state.error = "Audio playback failed. Please interact with the page first."; + state.isPlaying = false; + }); + } else { + audioElement.pause(); + } + } + + // Export this so it can be used by other components + function playAudio() { + togglePlayback(true); + } + + function pauseAudio() { + togglePlayback(false); + } + + // Make togglePlay available globally through state + state.togglePlay = () => { + state.isPlaying = !state.isPlaying; + togglePlayback(state.isPlaying); + }; + onMount(async () => { const data = await getGeneralData(); if (data) { @@ -55,31 +84,15 @@ $effect(() => { if (!audioElement) return; - - if (state.isPlaying && state.hasInteracted) { - audioElement.play().catch(() => { - state.error = "Audio playback failed. Please interact with the page first."; - state.isPlaying = false; - }); - } else { - audioElement.pause(); - } - - if (state.currentTime > 0) { - audioElement.currentTime = state.currentTime; - } + togglePlayback(state.isPlaying); }); {#if !state.hasInteracted}