fix: playing and pausing going back to initial state

This commit is contained in:
2025-04-18 21:06:21 +02:00
parent 1f13849b7a
commit 32bc8f4494

View File

@@ -11,20 +11,17 @@
if (!audioElement) return;
if (play && state.hasInteracted) {
audioElement.currentTime = state.currentTime;
audioElement.play().catch(() => {
state.error = 'Audio playback failed. Please interact with the page first.';
state.isPlaying = false;
});
audioElement.currentTime = state.currentTime;
} else {
state.currentTime = audioElement.currentTime;
audioElement.pause();
}
}
function playAudio() {
togglePlayback(true);
}
state.togglePlay = () => {
state.isPlaying = !state.isPlaying;
togglePlayback(state.isPlaying);
@@ -115,7 +112,7 @@
class="flex flex-col h-screen w-full items-center justify-center space-y-2 cursor-pointer"
onclick={() => {
state.hasInteracted = true;
playAudio()
togglePlayback(true);
}}
>
<p>Click anywhere on the screen</p>