I have this Svelte code:
Player.svelte:
<script>
import PlayerControls from './PlayerControls.svelte';
let audio;
</script>
<audio src={...} bind:this={audio} />
<PlayerControls {audio} />
PlayerControls.svelte:
<script>
import PlayIcon from '../icons/PlayIcon.svelte';
import PauseIcon from '../icons/PauseIcon.svelte';
export let audio;
const onClick = () => {
if (audio?.paused) audio.play();
else audio.pause();
};
</script>
{#if audio?.paused}
<PlayIcon {onClick} />
{:else}
<PauseIcon {onClick} />
{/if}
If I press the play icon, the icon doesn't change, but the audio starts, and if I click again, the audio stops, and the icon is unchanged. Seems like audio.paused "changes" only in the script, but not in the html. What is wrong here, and what I'm not understanding here about Svelte?
play()andpause()methods actually update thepauseproperty.