Files
oki-podcast-reader/src/routes/+page.svelte
T

60 lines
1.7 KiB
Svelte
Raw Normal View History

2023-02-22 10:24:39 +00:00
<script lang="ts">
2023-02-22 16:40:02 +00:00
import Audio from '$lib/components/audio/audio.svelte';
import { audio, _currentTime, _duration, _paused } from '$lib/components/audio/state';
2023-02-21 23:54:18 +00:00
2023-02-22 10:24:39 +00:00
const sources = {
syntax: '/example-syntax.mp3',
2023-02-22 16:40:02 +00:00
knomii: '/example-knomii.mp3',
2023-02-22 10:24:39 +00:00
} as const;
2023-02-21 23:54:18 +00:00
</script>
2023-02-22 16:40:02 +00:00
<pre>
{JSON.stringify($audio, null, 3)}
</pre>
2023-02-21 23:54:18 +00:00
<h1>Demo</h1>
2023-02-22 16:40:02 +00:00
<Audio on:progress={(e) => console.log(e.detail)} autoplay={false} />
<progress
style="width: 960px; max-width:100%"
data-paused={$_paused ? 'true' : 'false'}
max={$_duration}
value={$_currentTime}
/>
<h5>Load Audio</h5>
<button type="button" on:click={() => audio.load(sources['syntax'], { paused: false })}
>Syntax</button
2023-02-22 00:29:57 +00:00
>
2023-02-22 16:40:02 +00:00
<button type="button" on:click={() => audio.load(sources['knomii'], { paused: false })}
>Knomii</button
>
<button type="button" on:click={() => audio.unload()}>None</button>
2023-02-22 00:30:12 +00:00
2023-02-22 16:40:02 +00:00
<h5>Custom audio controls</h5>
2023-02-21 23:54:18 +00:00
2023-02-22 16:40:02 +00:00
<h6>Audio Actions</h6>
2023-02-21 23:54:18 +00:00
2023-02-22 16:40:02 +00:00
<button type="button" on:click={audio.play}>Play</button>
<button type="button" on:click={audio.pause}>Pause</button>
<button type="button" on:click={audio.toggle_pause}>Toggle</button>
2023-02-21 23:54:18 +00:00
2023-02-22 16:40:02 +00:00
<h6>Seeking</h6>
2023-02-21 23:54:18 +00:00
2023-02-22 16:40:02 +00:00
<button type="button" on:click={() => audio.seek(30)}>Go to 30s</button>
<!-- <button type="button" on:click={() => (currentTime = currentTime + 5)}>Skip 5s</button>
2023-02-22 00:29:57 +00:00
<button type="button" on:click={() => (currentTime = currentTime - 5)}>Rewind 5s</button>
2023-02-22 16:40:02 +00:00
<button type="button" on:click={() => (currentTime = duration - 30)}>Go to 30s before end</button> -->
2023-02-21 23:54:18 +00:00
2023-02-22 16:40:02 +00:00
<h6>Playback Rate</h6>
2023-02-21 23:54:18 +00:00
2023-02-22 16:40:02 +00:00
{#each [0.5, 1, 2, 3] as rate}
<button type="button" on:click={() => audio.setPlaybackRate(rate)}>{rate}x</button>
{/each}
2023-02-21 23:54:18 +00:00
2023-02-22 16:40:02 +00:00
<h6>Volume</h6>
2023-02-21 23:54:18 +00:00
2023-02-22 16:40:02 +00:00
{#each [0, 0.25, 0.5, 0.75, 1] as v}
<button type="button" on:click={() => audio.setVolume(v)}>{v * 100}%</button>
{/each}