diff --git a/materialious/src/lib/components/player/Player.svelte b/materialious/src/lib/components/player/Player.svelte index 68afe180..1d34f4b0 100644 --- a/materialious/src/lib/components/player/Player.svelte +++ b/materialious/src/lib/components/player/Player.svelte @@ -61,6 +61,7 @@ import FullscreenToggle from './settings/FullscreenToggle.svelte'; import { AndroidPlayer } from '$lib/player/android'; import Timeline from './Timeline.svelte'; + import TouchControls from './TouchControls.svelte'; interface Props { data: { video: VideoPlay; content: ParsedDescription; playlistId: string | null }; @@ -97,7 +98,7 @@ let playerVolume = $state($playerPreferredVolumeStore); let playerVideoEndTimePretty: string = $state(''); let playerIsFullscreen = $state(false); - let playerInitalInteract = true; + let playerInitalInteract = $state(true); const playerVolumeSlider = new Slider({ onValueChange: (volumeToSet) => { @@ -111,11 +112,6 @@ step: 0.01 }); - let clickCount = $state(0); - let clickCounterTimeout: ReturnType; - - let seekDirection: 'forwards' | 'backwards' | undefined = $state(); - playertheatreModeIsActive.subscribe(async () => { await tick(); updateVideoPlayerHeight(); @@ -778,45 +774,6 @@ } } - function onVideoClick(type: 'pause' | 'seekLeft' | 'seekRight') { - seekDirection = undefined; - - if (!playerElement) return; - - if (isMobile() && playerInitalInteract) { - showPlayerUI(); - playerInitalInteract = false; - clickCount = 0; - return; - } - - clickCount++; - - if (clickCounterTimeout) clearTimeout(clickCounterTimeout); - - clickCounterTimeout = setTimeout(() => { - if (clickCount == 1) { - toggleVideoPlaybackStatus(); - } - clickCount = 0; - }, 200); - - if (clickCount < 2) return; - - if (type === 'seekLeft') { - seekDirection = 'backwards'; - playerElement.currentTime = Math.max(0, playerElement.currentTime - playerDoubleTapSeek); - } else if (type === 'pause') { - toggleFullscreen(); - } else { - seekDirection = 'forwards'; - playerElement.currentTime = Math.min( - playerMaxKnownTime, - playerElement.currentTime + playerDoubleTapSeek - ); - } - } - onDestroy(async () => { if (Capacitor.getPlatform() === 'android') { await setStatusBarColor(); @@ -836,7 +793,6 @@ if (watchProgressInterval) clearInterval(watchProgressInterval); if (sabrAdapter) sabrAdapter.dispose(); - if (clickCounterTimeout) clearTimeout(clickCounterTimeout); if (showPlayerUiTimeout) clearTimeout(showPlayerUiTimeout); if (player) { @@ -887,31 +843,15 @@

{/if} -
-
-
onVideoClick('seekLeft')} role="presentation"> - {#if clickCount > 1 && seekDirection === 'backwards'} -
-

-{(clickCount - 1) * playerDoubleTapSeek}

-
- {/if} -
-
onVideoClick('pause')} role="presentation"> -
- {#if playerIsBuffering} - - {/if} -
-
-
onVideoClick('seekRight')} role="presentation"> - {#if clickCount > 1 && seekDirection === 'forwards'} -
-

+{(clickCount - 1) * playerDoubleTapSeek}

-
- {/if} -
-
-
+ {#if showControls}
+ import { isMobile } from '$lib/misc'; + import { playerDoubleTapSeek } from '$lib/player'; + import { onDestroy } from 'svelte'; + + let { + playerElement, + showPlayerUI, + toggleVideoPlaybackStatus, + toggleFullscreen, + playerMaxKnownTime = $bindable(), + playerIsBuffering = $bindable(), + playerInitalInteract = $bindable() + }: { + showPlayerUI: () => void; + toggleVideoPlaybackStatus: () => void; + toggleFullscreen: () => void; + playerElement: HTMLMediaElement | undefined; + playerMaxKnownTime: number; + playerIsBuffering: boolean; + playerInitalInteract: boolean; + } = $props(); + + let clickCount = $state(0); + let clickCounterTimeout: ReturnType; + + let seekDirection: 'forwards' | 'backwards' | undefined = $state(); + + function onTouchControl(type: 'pause' | 'seekLeft' | 'seekRight') { + seekDirection = undefined; + + if (!playerElement) return; + + if (isMobile() && playerInitalInteract) { + showPlayerUI(); + playerInitalInteract = false; + clickCount = 0; + return; + } + + clickCount++; + + if (clickCounterTimeout) clearTimeout(clickCounterTimeout); + + clickCounterTimeout = setTimeout(() => { + if (clickCount == 1) { + toggleVideoPlaybackStatus(); + } + clickCount = 0; + }, 200); + + if (clickCount < 2) return; + + if (type === 'seekLeft') { + seekDirection = 'backwards'; + playerElement.currentTime = Math.max(0, playerElement.currentTime - playerDoubleTapSeek); + } else if (type === 'pause') { + toggleFullscreen(); + } else { + seekDirection = 'forwards'; + playerElement.currentTime = Math.min( + playerMaxKnownTime, + playerElement.currentTime + playerDoubleTapSeek + ); + } + } + + onDestroy(() => { + if (clickCounterTimeout) clearTimeout(clickCounterTimeout); + }); + + +
+
+
onTouchControl('seekLeft')} role="presentation"> + {#if clickCount > 1 && seekDirection === 'backwards'} +
+

-{(clickCount - 1) * playerDoubleTapSeek}

+
+ {/if} +
+
onTouchControl('pause')} role="presentation"> +
+ {#if playerIsBuffering} + + {/if} +
+
+
onTouchControl('seekRight')} role="presentation"> + {#if clickCount > 1 && seekDirection === 'forwards'} +
+

+{(clickCount - 1) * playerDoubleTapSeek}

+
+ {/if} +
+
+
+ +