Improve Volume Handling

This commit is contained in:
Neshura 2024-04-22 20:04:12 +02:00
parent 115d30dc67
commit d1903045a4
Signed by: Neshura
GPG key ID: B6983AAA6B9A7A6C

View file

@ -126,11 +126,20 @@
source.pause();
}
$effect(() => {
if (source) {
source.volume = volume;
function changeVolume(change: number) {
if (volume + change > 1) {
volume = 1;
}
else if (volume + change < 0) {
volume = 0;
}
else {
volume = toFixedNumber(volume + change, 2, 10) ;
}
if (currentSong.source) {
currentSong.source.volume = volume;
}
});
function progressPercent() {
return progress / duration * 100 || 0;
@ -175,6 +184,8 @@
<p class="border p-2">Volume: {volume}</p>
<p class="border p-2">{displayTime(progress)}/{displayTime(duration)}</p>
<p class="border p-2">{progressPercent().toFixed(2)}%</p>
<Button class="border p-2" onclick={() => changeVolume(-0.05)}>-</Button>
<Button class="border p-2" onclick={() => changeVolume(0.05)}>+</Button>
{#if isPaused}
<Button onclick={play}>Play</Button>
{:else}