Rajaniraiyn / svelte-sound

sound interactions made easy
https://rajaniraiyn.github.io/svelte-sound/
MIT License
46 stars 2 forks source link

How to pause audio? #4

Closed antonkristiono closed 1 year ago

antonkristiono commented 1 year ago

how to pause the audio

Rajaniraiyn commented 1 year ago

Thanks @antonkristiono to reaching out. You can pause/stop the audio by adding another event listener as of v0.3.0

<script lang="ts">
  import { sound } from "svelte-sound";
  import click_mp3 from "/assets/click.mp3";

  let count: number = 0
  const increment = () => {
    count += 1
  }
</script>

<!-- below the sound starts when "mouseover" event is triggered and stops when "mouseleave" event is triggered -->
<button on:click={increment} use:sound={{src:click_mp3, events:["mouseover", "mouseleave"] }}> 
  count is {count}
</button>

So, basically you have to just add another event to the events array and it will be used to stop the sound playback.

Please check out v0.5.0's FAQ

Rajaniraiyn commented 1 year ago

This issue has been fixed and there is no activity (response) from the reporter. so closing this issue