2023-02-21 23:54:18 +00:00
|
|
|
<script lang="ts">
|
2023-02-22 00:42:14 +00:00
|
|
|
import AudioA11yProgress from '$lib/components/audio-a11y-progress.svelte';
|
2023-02-21 23:54:18 +00:00
|
|
|
import { createEventDispatcher } from 'svelte';
|
|
|
|
|
import { usePlayer, type PlayerElement } from './audio';
|
|
|
|
|
|
|
|
|
|
// TODO: Abstract to a store so we can add actions like reqind 20s
|
|
|
|
|
|
|
|
|
|
export let src: string;
|
|
|
|
|
export let autoplay: boolean;
|
2023-02-22 00:25:18 +00:00
|
|
|
|
2023-02-22 00:42:14 +00:00
|
|
|
export let currentTime = 0;
|
|
|
|
|
export let muted = false;
|
|
|
|
|
export let paused = true;
|
|
|
|
|
export let playbackRate = 1;
|
|
|
|
|
export let volume = 0;
|
2023-02-21 23:54:18 +00:00
|
|
|
|
|
|
|
|
let audioElement: PlayerElement;
|
|
|
|
|
|
|
|
|
|
$: usePlayer(audioElement, 'playbackRate', playbackRate);
|
|
|
|
|
|
2023-02-22 00:25:18 +00:00
|
|
|
const dispatch = createEventDispatcher<{
|
|
|
|
|
playing: void;
|
|
|
|
|
finished: void;
|
|
|
|
|
paused: { currentTime: number };
|
|
|
|
|
progress: { currentTime: number };
|
|
|
|
|
seek: { currentTime: number };
|
|
|
|
|
rateChange: { playbackRate: number };
|
|
|
|
|
}>();
|
2023-02-21 23:54:18 +00:00
|
|
|
|
2023-02-22 00:42:14 +00:00
|
|
|
let duration = 0;
|
2023-02-21 23:54:18 +00:00
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
{#key src}
|
|
|
|
|
<audio
|
|
|
|
|
bind:this={audioElement}
|
|
|
|
|
{src}
|
|
|
|
|
{autoplay}
|
|
|
|
|
bind:currentTime
|
|
|
|
|
bind:duration
|
|
|
|
|
bind:paused
|
|
|
|
|
bind:muted
|
|
|
|
|
bind:volume
|
|
|
|
|
preload="metadata"
|
2023-02-22 00:25:18 +00:00
|
|
|
controls={false}
|
2023-02-22 00:42:14 +00:00
|
|
|
on:timeupdate={() => dispatch('progress', { currentTime })}
|
|
|
|
|
on:playing={() => dispatch('playing')}
|
|
|
|
|
on:pause={() => dispatch('paused', { currentTime })}
|
|
|
|
|
on:ratechange={() => dispatch('rateChange', { playbackRate })}
|
|
|
|
|
on:ended={() => dispatch('finished')}
|
|
|
|
|
on:seeked={() => dispatch('seek', { currentTime })}
|
|
|
|
|
on:durationchange={() => console.log('durationchange')}
|
|
|
|
|
on:loadeddata={() => console.log('loaded data')}
|
|
|
|
|
on:loadedmetadata={() => console.log('loadedmetadata')}
|
|
|
|
|
on:loadstart={() => console.log('load start')}
|
|
|
|
|
on:seeking={() => console.log('seeking')}
|
|
|
|
|
on:suspend={() => console.log('suspend')}
|
|
|
|
|
on:volumechange={() => console.log('volumechange')}
|
|
|
|
|
on:play={() => console.log('play')}
|
|
|
|
|
on:canplay={() => console.log('canplay')}
|
|
|
|
|
on:canplaythrough={() => console.log('canplaythrough')}
|
|
|
|
|
on:waiting={() => console.log('waiting')}
|
2023-02-21 23:54:18 +00:00
|
|
|
on:stalled={(e) => console.log('stalled', e)}
|
|
|
|
|
on:emptied={(e) => console.log('emptied', e)}
|
|
|
|
|
on:load={(e) => console.log('load', e)}
|
|
|
|
|
/>
|
2023-02-22 00:36:40 +00:00
|
|
|
<AudioA11yProgress {currentTime} {paused} {duration} />
|
2023-02-22 00:29:57 +00:00
|
|
|
<slot {duration} />
|
2023-02-21 23:54:18 +00:00
|
|
|
{/key}
|