feat: conditional CC rendering and click-to-play in Player mode
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,6 +1,10 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { session, upgradePreview, dismissUpgradeToast } from '$lib/stores/videoSession.svelte';
|
import { session, upgradePreview, dismissUpgradeToast } from '$lib/stores/videoSession.svelte';
|
||||||
import { setVideoElement } from '$lib/transport/playback';
|
import {
|
||||||
|
setVideoElement,
|
||||||
|
togglePlayPause as playbackTogglePlayPause,
|
||||||
|
toggleFullscreen,
|
||||||
|
} from '$lib/transport/playback';
|
||||||
import { preferences } from '$lib/stores/preferences.svelte';
|
import { preferences } from '$lib/stores/preferences.svelte';
|
||||||
import { parseVtt, getActiveCues, getActiveWords, type VttCue } from '$lib/utils/vttParser';
|
import { parseVtt, getActiveCues, getActiveWords, type VttCue } from '$lib/utils/vttParser';
|
||||||
import { getMediaServerPort } from '$lib/bindings/video';
|
import { getMediaServerPort } from '$lib/bindings/video';
|
||||||
@@ -14,14 +18,21 @@
|
|||||||
return `${r}, ${g}, ${b}`;
|
return `${r}, ${g}, ${b}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let {
|
||||||
|
captionsEnabled = $bindable(true),
|
||||||
|
}: {
|
||||||
|
captionsEnabled?: boolean;
|
||||||
|
} = $props();
|
||||||
|
|
||||||
let videoElement = $state<HTMLVideoElement | null>(null);
|
let videoElement = $state<HTMLVideoElement | null>(null);
|
||||||
let videoError = $state<string | null>(null);
|
let videoError = $state<string | null>(null);
|
||||||
let videoSrc = $state<string | null>(null);
|
let videoSrc = $state<string | null>(null);
|
||||||
let captionsEnabled = $state(true);
|
|
||||||
let showCaptionSettings = $state(false);
|
let showCaptionSettings = $state(false);
|
||||||
let parsedCues = $state<VttCue[]>([]);
|
let parsedCues = $state<VttCue[]>([]);
|
||||||
let mediaServerPort = $state<number | null>(null);
|
let mediaServerPort = $state<number | null>(null);
|
||||||
|
|
||||||
|
let isPlayerMode = $derived(preferences.appMode === 'player');
|
||||||
|
|
||||||
// Fetch media server port on mount
|
// Fetch media server port on mount
|
||||||
$effect(() => {
|
$effect(() => {
|
||||||
getMediaServerPort().then((port) => {
|
getMediaServerPort().then((port) => {
|
||||||
@@ -108,6 +119,30 @@
|
|||||||
showCaptionSettings = !showCaptionSettings;
|
showCaptionSettings = !showCaptionSettings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function handleVideoClick() {
|
||||||
|
if (isPlayerMode) {
|
||||||
|
playbackTogglePlayPause();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let clickTimer: ReturnType<typeof setTimeout> | null = null;
|
||||||
|
|
||||||
|
function handleVideoClickWithDelay(_e: MouseEvent) {
|
||||||
|
if (!isPlayerMode) return;
|
||||||
|
// Distinguish single click from double click
|
||||||
|
if (clickTimer) {
|
||||||
|
clearTimeout(clickTimer);
|
||||||
|
clickTimer = null;
|
||||||
|
// Double click
|
||||||
|
toggleFullscreen();
|
||||||
|
} else {
|
||||||
|
clickTimer = setTimeout(() => {
|
||||||
|
clickTimer = null;
|
||||||
|
playbackTogglePlayPause();
|
||||||
|
}, 250);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let lastTimeUpdate = 0;
|
let lastTimeUpdate = 0;
|
||||||
const TIME_UPDATE_INTERVAL = 66;
|
const TIME_UPDATE_INTERVAL = 66;
|
||||||
|
|
||||||
@@ -196,6 +231,7 @@
|
|||||||
onpause={handlePause}
|
onpause={handlePause}
|
||||||
onerror={handleError}
|
onerror={handleError}
|
||||||
onloadeddata={handleLoadedData}
|
onloadeddata={handleLoadedData}
|
||||||
|
onclick={handleVideoClickWithDelay}
|
||||||
preload="metadata"
|
preload="metadata"
|
||||||
playsinline
|
playsinline
|
||||||
>
|
>
|
||||||
@@ -219,7 +255,7 @@
|
|||||||
{/each}
|
{/each}
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
{#if parsedCues.length > 0}
|
{#if !isPlayerMode && parsedCues.length > 0}
|
||||||
<div class="cc-controls">
|
<div class="cc-controls">
|
||||||
<button
|
<button
|
||||||
class="cc-toggle"
|
class="cc-toggle"
|
||||||
@@ -234,7 +270,7 @@
|
|||||||
>⚙</button>
|
>⚙</button>
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
{#if showCaptionSettings}
|
{#if !isPlayerMode && showCaptionSettings}
|
||||||
<CaptionSettingsPanel onClose={() => (showCaptionSettings = false)} />
|
<CaptionSettingsPanel onClose={() => (showCaptionSettings = false)} />
|
||||||
{/if}
|
{/if}
|
||||||
{#if session.showUpgradeToast}
|
{#if session.showUpgradeToast}
|
||||||
|
|||||||
Reference in New Issue
Block a user