Add timestamp

This commit is contained in:
Ollie Taylor
2023-02-23 00:19:10 +00:00
parent f4e2e8d628
commit 5a4936f75d
2 changed files with 32 additions and 2 deletions
+14 -2
View File
@@ -1,7 +1,8 @@
import { dev } from '$app/environment';
import type { PlayerElement, PlayerMetadata } from '$lib/components/audio/types';
import { secondsToTimestamp } from '$lib/helper/s-to-timestamp';
import clamp from 'just-clamp';
import { writable } from 'svelte/store';
import { derived, writable } from 'svelte/store';
function log(...val: (string | number | boolean)[]) {
if (!dev) return;
@@ -23,6 +24,17 @@ export const __internal_audio_metadata = writable<PlayerMetadata>({
loading: false,
});
const state = derived(
[__internal_audio_metadata, __internal_audio_current_time],
([$metadata, $current_time]) => {
return {
current_time: $current_time,
timestamp: secondsToTimestamp($current_time),
...$metadata,
};
},
);
type HandleType = 'toggle' | 'set';
function play(type: HandleType = 'set') {
@@ -118,7 +130,7 @@ function skip(seconds: number, type: 'forward' | 'backward' = 'forward') {
}
export const audio = {
subscribe: __internal_audio_metadata.subscribe,
subscribe: state.subscribe,
play,
pause,
mute,