diff --git a/materialious/src/lib/Player.svelte b/materialious/src/lib/Player.svelte index 7ec3b189..b85f73cb 100644 --- a/materialious/src/lib/Player.svelte +++ b/materialious/src/lib/Player.svelte @@ -5,7 +5,7 @@ import { SponsorBlock, type Category } from 'sponsorblock-api'; import { onDestroy, onMount } from 'svelte'; import { get } from 'svelte/store'; - import type { MediaTimeUpdateEvent, PlayerSrc } from 'vidstack'; + import type { MediaTimeUpdateEvent, MediaVolumeChangeEvent, PlayerSrc } from 'vidstack'; import type { MediaPlayerElement } from 'vidstack/elements'; import { playerAlwaysLoop, @@ -38,6 +38,13 @@ const proxyVideos = get(playerProxyVideos); onMount(async () => { + try { + const defaultVolume = localStorage.getItem('volume'); + if (defaultVolume) { + player.volume = Number(defaultVolume); + } + } catch {} + if (playlistVideos) { player.addEventListener('end', () => { if (!playlistVideos) return; @@ -97,6 +104,12 @@ savePlayerPos(); }); + player.addEventListener('volume-change', (event: MediaVolumeChangeEvent) => { + try { + localStorage.setItem('volume', event.detail.volume.toString()); + } catch {} + }); + if (get(sponsorBlockCategories)) { const currentCategories = get(sponsorBlockCategories); @@ -152,10 +165,12 @@ } if (get(playerSavePlaybackPosition)) { - const playerPos = localStorage.getItem(`v_${data.video.videoId}`); - if (playerPos) { - player.currentTime = Number(playerPos); - } + try { + const playerPos = localStorage.getItem(`v_${data.video.videoId}`); + if (playerPos) { + player.currentTime = Number(playerPos); + } + } catch {} } } else { src = [ @@ -197,13 +212,15 @@ }); function savePlayerPos() { - if (get(playerSavePlaybackPosition) && player.currentTime) { - if (player.currentTime < player.duration - 10 && player.currentTime > 10) { - localStorage.setItem(`v_${data.video.videoId}`, player.currentTime.toString()); - } else { - localStorage.removeItem(`v_${data.video.videoId}`); + try { + if (get(playerSavePlaybackPosition) && player.currentTime) { + if (player.currentTime < player.duration - 10 && player.currentTime > 10) { + localStorage.setItem(`v_${data.video.videoId}`, player.currentTime.toString()); + } else { + localStorage.removeItem(`v_${data.video.videoId}`); + } } - } + } catch {} } onDestroy(() => { @@ -224,6 +241,7 @@ streamType={data.video.hlsUrl ? 'live' : 'on-demand'} viewType={audioMode ? 'audio' : 'video'} playsInline={true} + keep-alive {src} > diff --git a/materialious/src/lib/Thumbnail.svelte b/materialious/src/lib/Thumbnail.svelte index 806b485d..83f9457a 100644 --- a/materialious/src/lib/Thumbnail.svelte +++ b/materialious/src/lib/Thumbnail.svelte @@ -18,7 +18,11 @@ let progress: string | null; if (get(playerSavePlaybackPosition)) { - progress = localStorage.getItem(`v_${video.videoId}`); + try { + progress = localStorage.getItem(`v_${video.videoId}`); + } catch { + progress = null; + } } else { progress = null; } diff --git a/materialious/src/lib/misc.ts b/materialious/src/lib/misc.ts index a8099c05..d3cd83a7 100644 --- a/materialious/src/lib/misc.ts +++ b/materialious/src/lib/misc.ts @@ -40,7 +40,6 @@ export interface PhasedDescription { export function phaseDescription(content: string): PhasedDescription { const timestamps: { title: string; time: number; timePretty: string; }[] = []; - console.log(content); const lines = content.split('\n'); const urlRegex = / { await deleteHistory(); history = []; - Object.keys(localStorage).forEach((key) => { - if (key.startsWith('v_')) { - localStorage.removeItem(key); - } - }); + try { + Object.keys(localStorage).forEach((key) => { + if (key.startsWith('v_')) { + localStorage.removeItem(key); + } + }); + } catch {} }} > delete_sweep