I'm trying to play a sound effect when a page loads using Svelte. I tried onMount, but there is no sound.
Here is what I have so far:
<script lang="ts">
import { onMount } from 'svelte';
let celebration: HTMLAudioElement;
onMount(() => {
celebration.play();
setTimeout(() => {
celebration.pause();
celebration.currentTime = 0;
}, 1000);
});
</script>
<audio
src='https://sveltejs.github.io/assets/music/strauss.mp3'
preload="auto"
bind:this={celebration}
controls
>
<track kind="captions" />
</audio>