2023-02-22 16:40:02 +00:00
|
|
|
<script lang="ts">
|
|
|
|
|
import {
|
2023-02-22 23:41:29 +00:00
|
|
|
__internal_audio_current_time,
|
|
|
|
|
__internal_audio_element,
|
|
|
|
|
__internal_audio_metadata,
|
|
|
|
|
__internal_audio_src,
|
|
|
|
|
} from '$lib/components/audio/store';
|
|
|
|
|
import type { PlayerElement } from '$lib/components/audio/types';
|
2023-02-23 00:39:46 +00:00
|
|
|
import { isBoolean, isNumber } from '$lib/helper/check';
|
2023-02-22 16:40:02 +00:00
|
|
|
|
2023-02-22 23:41:29 +00:00
|
|
|
let element: PlayerElement;
|
2023-02-22 16:40:02 +00:00
|
|
|
let currentTime = 0;
|
|
|
|
|
let muted = false;
|
|
|
|
|
|
2023-02-22 23:41:29 +00:00
|
|
|
$: src = $__internal_audio_src;
|
|
|
|
|
$: __internal_audio_element.set(element);
|
|
|
|
|
$: __internal_audio_current_time.set(currentTime);
|
|
|
|
|
$: __internal_audio_metadata.update((x) => ({ ...x, muted }));
|
2023-02-22 16:40:02 +00:00
|
|
|
</script>
|
|
|
|
|
|
2023-02-23 00:48:21 +00:00
|
|
|
{#key src}
|
2023-02-22 23:41:29 +00:00
|
|
|
<audio
|
|
|
|
|
bind:this={element}
|
|
|
|
|
{src}
|
|
|
|
|
autoplay={false}
|
|
|
|
|
bind:currentTime
|
|
|
|
|
bind:muted
|
|
|
|
|
preload="metadata"
|
|
|
|
|
controls={false}
|
|
|
|
|
on:canplay={(e) => false && console.log('canplay', e)}
|
|
|
|
|
on:canplaythrough={(e) => false && console.log('canplaythrough', e)}
|
|
|
|
|
on:timeupdate={(e) => false && console.log('progress', e)}
|
|
|
|
|
on:loadedmetadata={(e) => false && console.log('loadedmetadata', e)}
|
|
|
|
|
on:suspend={(e) => false && console.log('suspend', e)}
|
|
|
|
|
on:seeked={(e) => false && console.log('seeked', e)}
|
|
|
|
|
on:play={(e) => false && console.log('play', e)}
|
|
|
|
|
on:waiting={(e) => console.log('waiting', e)}
|
|
|
|
|
on:stalled={(e) => console.log('stalled', e)}
|
|
|
|
|
on:load={(e) => console.log('load', e)}
|
2023-02-23 00:21:37 +00:00
|
|
|
on:emptied={() => {
|
2023-02-22 23:41:29 +00:00
|
|
|
// TODO: reset player state
|
|
|
|
|
// console.log('emptied', e);
|
|
|
|
|
}}
|
|
|
|
|
on:loadeddata={() => {
|
|
|
|
|
__internal_audio_metadata.update((m) => ({ ...m, loading: false }));
|
|
|
|
|
}}
|
|
|
|
|
on:loadstart={() => {
|
|
|
|
|
__internal_audio_metadata.update((m) => ({ ...m, loading: true }));
|
|
|
|
|
}}
|
|
|
|
|
on:playing={(e) => {
|
2023-02-23 00:21:37 +00:00
|
|
|
// @ts-expect-error event is not fully typed
|
2023-02-22 23:41:29 +00:00
|
|
|
const is_paused = e.target.paused;
|
2023-02-23 00:39:46 +00:00
|
|
|
if (!isBoolean(is_paused)) return;
|
2023-02-22 23:41:29 +00:00
|
|
|
__internal_audio_metadata.update((m) => ({ ...m, paused: is_paused }));
|
|
|
|
|
}}
|
|
|
|
|
on:pause={(e) => {
|
2023-02-23 00:21:37 +00:00
|
|
|
// @ts-expect-error event is not fully typed
|
2023-02-22 23:41:29 +00:00
|
|
|
const is_paused = e.target.paused;
|
2023-02-23 00:39:46 +00:00
|
|
|
if (!isBoolean(is_paused)) return;
|
2023-02-22 23:41:29 +00:00
|
|
|
__internal_audio_metadata.update((m) => ({ ...m, paused: is_paused }));
|
|
|
|
|
}}
|
2023-02-23 00:39:46 +00:00
|
|
|
on:ratechange={(e) => {
|
|
|
|
|
// @ts-expect-error event is not fully typed
|
|
|
|
|
const playbackRate = e.target.playbackRate;
|
|
|
|
|
if (!isNumber(playbackRate)) return;
|
|
|
|
|
__internal_audio_metadata.update((m) => ({ ...m, playbackRate }));
|
|
|
|
|
}}
|
2023-02-22 23:41:29 +00:00
|
|
|
on:durationchange={(e) => {
|
2023-02-23 00:21:37 +00:00
|
|
|
// @ts-expect-error event is not fully typed
|
2023-02-23 00:39:46 +00:00
|
|
|
const duration = e.target?.duration;
|
|
|
|
|
if (!isNumber(duration)) return;
|
|
|
|
|
__internal_audio_metadata.update((m) => ({ ...m, duration }));
|
2023-02-22 23:41:29 +00:00
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
<!-- <AudioA11yProgress {currentTime} {paused} {duration} /> -->
|
2023-02-23 00:48:21 +00:00
|
|
|
{/key}
|