diff --git a/materialious/src/lib/Player.svelte b/materialious/src/lib/Player.svelte index d1faa62f..fb17910b 100644 --- a/materialious/src/lib/Player.svelte +++ b/materialious/src/lib/Player.svelte @@ -21,13 +21,13 @@ import { getDynamicTheme } from './theme'; export let data: { video: VideoPlay; content: PhasedDescription; playlistId: string | null }; - export let currentTime: number = 0; export let audioMode = false; export let player: MediaPlayerElement; export let isSyncing: boolean = false; let src: PlayerSrc = []; let categoryBeingSkipped = ''; + let playerIsLive = false; export function seekTo(time: number) { if (typeof player !== 'undefined') { @@ -38,14 +38,8 @@ const proxyVideos = get(playerProxyVideos); onMount(async () => { - try { - const defaultVolume = localStorage.getItem('volume'); - if (defaultVolume) { - player.volume = Number(defaultVolume); - } - } catch {} - if (!data.video.hlsUrl) { + playerIsLive = false; if (data.video.captions) { data.video.captions.forEach(async (caption) => { player.textTracks.add({ @@ -81,10 +75,6 @@ }); } - player.addEventListener('time-update', () => { - currentTime = player.currentTime; - }); - player.addEventListener('pause', () => { savePlayerPos(); }); @@ -121,6 +111,10 @@ } if (get(playerDash)) { + player.addEventListener('dash-can-play', () => { + loadPlayerPos(); + }); + src = [{ src: data.video.dashUrl + '?local=true', type: 'application/dash+xml' }]; } else { let formattedSrc; @@ -138,17 +132,11 @@ width: Number(quality[0]) }; }); - } - if (get(playerSavePlaybackPosition)) { - try { - const playerPos = localStorage.getItem(`v_${data.video.videoId}`); - if (playerPos) { - player.currentTime = Number(playerPos); - } - } catch {} + loadPlayerPos(); } } else { + playerIsLive = true; src = [ { src: data.video.hlsUrl + '?local=true', @@ -189,7 +177,20 @@ document.documentElement.style.setProperty('--audio-bg', currentTheme['--surface']); }); + function loadPlayerPos() { + if (get(playerSavePlaybackPosition)) { + try { + const playerPos = localStorage.getItem(`v_${data.video.videoId}`); + if (playerPos) { + player.currentTime = Number(playerPos); + } + } catch {} + } + } + function savePlayerPos() { + if (data.video.hlsUrl) return; + try { if (get(playerSavePlaybackPosition) && player.currentTime) { if (player.currentTime < player.duration - 10 && player.currentTime > 10) { @@ -216,7 +217,7 @@ autoPlay={$playerAutoPlay && !isSyncing} loop={$playerAlwaysLoop} title={data.video.title} - streamType={data.video.hlsUrl ? 'live' : 'on-demand'} + streamType={playerIsLive ? 'live' : 'on-demand'} viewType={audioMode ? 'audio' : 'video'} keep-alive {src} diff --git a/materialious/src/lib/Search.svelte b/materialious/src/lib/Search.svelte index af23284d..74b8ce6a 100644 --- a/materialious/src/lib/Search.svelte +++ b/materialious/src/lib/Search.svelte @@ -1,9 +1,12 @@ - (showVideoPreview = false)} + on:focus={() => {}} + role="region" > - {#if loading} - - {:else if loaded} - Thumbnail for video - {:else} -

{$_('thumbnail.failedToLoadImage')}

- {/if} - {#if progress} - - {/if} - {#if !('liveVideo' in video) || !video.liveVideo} - {#if video.lengthSeconds !== 0} -
-  {videoLength(video.lengthSeconds)}  + + {#if loading} + + {:else if loaded} + {#if showVideoPreview && videoPreview} +
+ +
+ {:else} + Thumbnail for video + {/if} + {:else} +

{$_('thumbnail.failedToLoadImage')}

+ {/if} + {#if progress} + + {/if} + {#if !('liveVideo' in video) || !video.liveVideo} + {#if video.lengthSeconds !== 0} +
+  {videoLength(video.lengthSeconds)}  +
+ {/if} + {:else} +
+ {$_('thumbnail.live')}
{/if} - {:else} -
- {$_('thumbnail.live')} -
+
+ {#if showVideoPreview && videoPreview} + {/if} - +
+
+ +
+ +
+ +
@@ -689,9 +724,6 @@ -
- -
{#each pages as page} {#if !page.requiresAuth || isLoggedIn} @@ -766,4 +798,10 @@ form { margin: 1em 0; } + + @media screen and (max-width: 650px) { + dialog.right { + width: 100%; + } + } diff --git a/materialious/src/routes/watch/[slug]/+page.svelte b/materialious/src/routes/watch/[slug]/+page.svelte index 12b71d63..5c07109d 100644 --- a/materialious/src/routes/watch/[slug]/+page.svelte +++ b/materialious/src/routes/watch/[slug]/+page.svelte @@ -46,7 +46,6 @@ let theatreMode = get(playerTheatreModeByDefault); let audioMode = get(playerListenByDefault); - let currentTime: number; let seekTo: (time: number) => void; let player: MediaPlayerElement; @@ -357,14 +356,7 @@
{#key data.video.videoId} - + {/key}
{data.video.title}
diff --git a/materialious/src/store.ts b/materialious/src/store.ts index 6004937b..cfb8f54f 100644 --- a/materialious/src/store.ts +++ b/materialious/src/store.ts @@ -24,6 +24,7 @@ export const playerAutoplayNextByDefault = persisted('autoplayNextByDefault', fa export const returnYtDislikes = persisted('returnYtDislikes', true); export const interfaceSearchSuggestions = persisted('searchSuggestions', true); +export const interfacePreviewVideoOnHover = persisted('previewVideoOnHover', true); export const auth: Writable = persisted( 'authToken',