2023-02-22 10:24:39 +00:00
|
|
|
<script lang="ts">
|
2023-02-24 13:15:34 +00:00
|
|
|
import { audio } from '$lib';
|
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-23 12:09:08 +00:00
|
|
|
|
|
|
|
|
let current_time = 0;
|
|
|
|
|
$: current_time = $audio.current_time;
|
2023-02-21 23:54:18 +00:00
|
|
|
</script>
|
|
|
|
|
|
2023-02-22 23:41:29 +00:00
|
|
|
<pre>{JSON.stringify($audio, null, 3)}</pre>
|
2023-02-22 16:40:02 +00:00
|
|
|
|
2023-02-21 23:54:18 +00:00
|
|
|
<h1>Demo</h1>
|
2023-02-23 12:09:08 +00:00
|
|
|
<a href="/another-page">Another Page</a>
|
2023-02-22 16:40:02 +00:00
|
|
|
|
|
|
|
|
<h5>Load Audio</h5>
|
2023-02-24 14:43:33 +00:00
|
|
|
<button
|
|
|
|
|
type="button"
|
|
|
|
|
on:click={() => audio.load(sources['syntax'], { autoplay: true, start_at: 45 })}>Syntax</button
|
2023-02-24 14:01:43 +00:00
|
|
|
>
|
|
|
|
|
<button type="button" on:click={() => audio.load(sources['knomii'], { autoplay: false })}
|
|
|
|
|
>Knomii</button
|
|
|
|
|
>
|
2023-02-22 16:40:02 +00:00
|
|
|
<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 23:41:29 +00:00
|
|
|
<h6>Play / Pause Actions</h6>
|
|
|
|
|
|
|
|
|
|
<button type="button" on:click={() => audio.play()}>Play</button>
|
|
|
|
|
<button type="button" on:click={() => audio.pause()}>Pause</button>
|
|
|
|
|
<button type="button" on:click={() => audio.pause('toggle')}>Toggle</button>
|
|
|
|
|
|
2023-02-22 16:40:02 +00:00
|
|
|
<h6>Audio Actions</h6>
|
2023-02-21 23:54:18 +00:00
|
|
|
|
2023-02-22 23:41:29 +00:00
|
|
|
<button type="button" on:click={() => audio.mute()}>Mute</button>
|
|
|
|
|
<button type="button" on:click={() => audio.unmute()}>Unmute</button>
|
|
|
|
|
<button type="button" on:click={() => audio.mute('toggle')}>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-23 12:09:08 +00:00
|
|
|
<input
|
|
|
|
|
type="range"
|
|
|
|
|
min={0}
|
|
|
|
|
max={$audio.duration}
|
|
|
|
|
style="width:100%"
|
|
|
|
|
bind:value={current_time}
|
|
|
|
|
on:change={(e) => audio.seek(parseInt(e.currentTarget.value))}
|
|
|
|
|
/>
|
|
|
|
|
|
2023-02-22 23:41:29 +00:00
|
|
|
<button type="button" on:click={() => audio.seek(30)}>Go to 30s from start </button>
|
|
|
|
|
<button type="button" on:click={() => audio.seek(30, 'from-end')}>Go to 30s from end</button>
|
|
|
|
|
<button type="button" on:click={() => audio.skip(10, 'forward')}>Skip 10s</button>
|
|
|
|
|
<button type="button" on:click={() => audio.skip(10, 'backward')}>Rewind 10s</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}
|