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

68 lines
1.8 KiB
Svelte
Raw Normal View History

2023-02-22 10:24:39 +00:00
<script lang="ts">
2023-02-21 23:54:18 +00:00
import Audio from '$lib/components/audio.svelte';
2023-02-22 10:24:39 +00:00
const sources = {
syntax: '/example-syntax.mp3',
knomii: '/example-knomii.mp3'
} as const;
2023-02-21 23:54:18 +00:00
let playbackRate = 1;
let volume = 0.5;
let paused = true;
let currentTime = 0;
2023-02-22 10:24:39 +00:00
let src = '';
2023-02-21 23:54:18 +00:00
</script>
<h1>Demo</h1>
<h5>Native audio controls</h5>
2023-02-22 00:29:04 +00:00
<Audio
on:progress={(e) => console.log(e.detail)}
2023-02-22 10:24:39 +00:00
{src}
2023-02-22 00:29:04 +00:00
autoplay={false}
{volume}
{playbackRate}
{paused}
bind:currentTime
2023-02-22 00:29:57 +00:00
let:duration
>
2023-02-22 10:24:39 +00:00
<progress
style="width: 800px; max-width:100%"
data-paused={paused ? 'true' : 'false'}
max={duration}
value={currentTime}
/>
<h5>Load Audio</h5>
<button type="button" on:click={() => (src = sources['syntax'])}>Syntax</button>
<button type="button" on:click={() => (src = sources['knomii'])}>Knomii</button>
<button type="button" on:click={() => (src = '')}>None</button>
2023-02-22 00:30:12 +00:00
2023-02-22 00:29:57 +00:00
<h5>Custom audio controls</h5>
2023-02-21 23:54:18 +00:00
2023-02-22 00:29:57 +00:00
<h6>Audio Actions</h6>
2023-02-21 23:54:18 +00:00
2023-02-22 00:29:57 +00:00
<button type="button" on:click={() => (paused = false)}>Play</button>
<button type="button" on:click={() => (paused = true)}>Pause</button>
<button type="button" on:click={() => (paused = !paused)}>Toggle</button>
2023-02-21 23:54:18 +00:00
2023-02-22 00:29:57 +00:00
<h6>Seeking</h6>
2023-02-21 23:54:18 +00:00
2023-02-22 00:29:57 +00:00
<button type="button" on:click={() => (currentTime = currentTime + 5)}>Skip 5s</button>
<button type="button" on:click={() => (currentTime = currentTime - 5)}>Rewind 5s</button>
<button type="button" on:click={() => (currentTime = 30)}>Go to 30s</button>
<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 00:29:57 +00:00
<h6>Playback Rate</h6>
2023-02-21 23:54:18 +00:00
2023-02-22 00:29:57 +00:00
{#each [0.5, 1, 2, 3] as rate}
<button type="button" on:click={() => (playbackRate = rate)}>{rate}x</button>
{/each}
2023-02-21 23:54:18 +00:00
2023-02-22 00:29:57 +00:00
<h6>Volume</h6>
2023-02-21 23:54:18 +00:00
2023-02-22 00:29:57 +00:00
{#each [0, 0.25, 0.5, 0.75, 1] as v}
<button type="button" on:click={() => (volume = v)}>{v * 100}%</button>
{/each}
</Audio>