diff --git a/README.md b/README.md index a90c1e7..c0397a7 100644 --- a/README.md +++ b/README.md @@ -61,6 +61,27 @@ To avoid re-encoding, keep **Settings → Live recording preset** on **Original Chaturbate stream extraction uses IPv4 by default to avoid unreachable IPv6 routes in containers. The **Use IPv4 for stream extraction** setting can be disabled on networks requiring IPv6. It applies to yt-dlp's metadata and playlist requests; FFmpeg makes its own connections while capturing. If errors persist, check connectivity from the Open EasyX container and the recording error in Activity. +## Video player gestures and casting + +On a phone or tablet the video player supports: + +| Gesture | Action | +| --- | --- | +| Tap | show or hide the controls | +| Double tap right / left | skip 10 seconds forward / back (each further quick tap adds 10 seconds) | +| Press and hold on the right | play at 2× while held | +| Pinch with two fingers | zoom in or out (drag with one finger while zoomed; tap the zoom badge to reset) | + +With a mouse, a click plays or pauses, a double click toggles fullscreen and holding on the right plays at 2×. The keyboard keeps Space/K, ←/→, M and F. + +The cast button sends the video to a TV: + +- **Chromecast / Google TV** works in Chrome or Edge when Open EasyX is opened over **HTTPS** (for example through a Synology or Nginx reverse proxy with a certificate); Google only offers its cast API on secure pages. Over plain `http://NAS:3210`, use the browser menu (⋮ → Cast…) to cast the tab. +- **AirPlay** works from Safari on iPhone, iPad and Mac, also over plain HTTP. +- Chrome on Android may also offer its built-in remote playback for the video. + +The TV loads the file directly from Open EasyX, so open the app by the NAS address or host name (not `localhost`). Chromecast plays MP4 (H.264/AAC) and WebM; other formats need one of the re-encoding recording presets. + ## Local development Requirements: Node.js 22.5 or newer, Git, FFmpeg, and the downloader helpers used by the plugins you enable. diff --git a/src/Player.test.tsx b/src/Player.test.tsx index 88feb0b..62acf77 100644 --- a/src/Player.test.tsx +++ b/src/Player.test.tsx @@ -38,13 +38,6 @@ describe("photo player", () => { }); describe("video player", () => { - it("offers and restores audio amplification up to 300 percent", () => { - vi.stubGlobal("localStorage", { getItem: (key: string) => key === "open-easyx.player-audio-boost" ? "3" : null, setItem: vi.fn() }); - const html = renderToStaticMarkup(); - expect(html).toContain('aria-label="Audio boost"'); - expect(html).toContain(''); - }); - it("asks the browser to autoplay a video reached from the previous item", () => { vi.stubGlobal("localStorage", { getItem: () => null, setItem: vi.fn() }); const html = renderToStaticMarkup(); @@ -72,3 +65,13 @@ describe("delete from the player", () => { expect(html).not.toContain("watch-delete"); }); }); + +describe("video player gestures and casting", () => { + it("renders the gesture surface and a cast button", () => { + vi.stubGlobal("localStorage", { getItem: () => null, setItem: vi.fn() }); + const html = renderToStaticMarkup(); + expect(html).toContain('class="player-surface"'); + expect(html).toContain('aria-label="Cast to a TV"'); + expect(html).not.toContain("player-zoom-reset"); + }); +}); diff --git a/src/Player.tsx b/src/Player.tsx index b29f394..5677b86 100644 --- a/src/Player.tsx +++ b/src/Player.tsx @@ -1,12 +1,14 @@ -import { useEffect, useRef, useState } from "react"; -import { AlertTriangle, ArrowLeft, Captions, Check, Clock3, Grid3X3, Heart, LoaderCircle, Maximize, Minimize, Pause, Play, RefreshCw, Trash2, Upload, Volume2, VolumeX } from "lucide-react"; +import { useEffect, useRef, useState, type PointerEvent as ReactPointerEvent } from "react"; +import { AlertTriangle, ArrowLeft, Captions, Cast, Check, ChevronsLeft, ChevronsRight, FastForward, ZoomOut, Clock3, Grid3X3, Heart, LoaderCircle, Maximize, Minimize, Pause, Play, RefreshCw, Trash2, Upload, Volume2, VolumeX } from "lucide-react"; import { api } from "./api"; import { initialAutoplay, nextMediaId, PHOTO_AUTOPLAY_SECONDS } from "./playback"; import { loadPlayerAudio, savePlayerAudio } from "./player-audio"; -import { createPlayerAudioBoost, loadPlayerAudioBoost, MAX_AUDIO_BOOST, savePlayerAudioBoost, type PlayerAudioBoost } from "./player-audio-boost"; import { monitorVideoStalls } from "./video-stall-recovery"; import { usePlayerFullscreen } from "./player-fullscreen"; import { createControlsAutoHide } from "./player-controls"; +import { clampZoom, createPlayerGestures, HOLD_PLAYBACK_RATE, NO_ZOOM, pinchZoom, SEEK_STEP_SECONDS, type GesturePoint, type GestureSide, type ZoomState } from "./player-gestures"; +import { usePlayerCast } from "./player-cast"; +import "./player-gestures.css"; import "./player.css"; import "./photo-player.css"; import "./watch-page.css"; @@ -34,11 +36,8 @@ export function PlayerViewer({ media, context, autoStart = false, close, favorit media: Media; context: PlaybackContext; autoStart?: boolean; close: () => void; remove?: (media: Media) => Promise; favorite: (media: Media, value: boolean) => void; advance: (media: Media) => void; setNotice: (value: string) => void; }) { - const video = useRef(null); const player = useRef(null); const lastSaved = useRef(0); + const video = useRef(null); const player = useRef(null); const surface = useRef(null); const lastSaved = useRef(0); const initialAudio = useRef(loadPlayerAudio()); - const audioBoost = useRef(undefined); - const selectedBoost = useRef(loadPlayerAudioBoost()); - const [boost, setBoost] = useState(selectedBoost.current); const recoveryPosition = useRef(undefined); const [playbackError, setPlaybackError] = useState(""); const [retry, setRetry] = useState(0); @@ -52,22 +51,17 @@ export function PlayerViewer({ media, context, autoStart = false, close, favorit const [captionMenu, setCaptionMenu] = useState(false); const captionMenuOpen = useRef(false); captionMenuOpen.current = captionMenu; const [subtitleTrack, setSubtitleTrack] = useState(() => localStorage.getItem("open-easyx.subtitle-track") || "original"); const [subtitles, setSubtitles] = useState({ status: "disabled", progress: 0, sourceLanguage: "", error: "", tracks: [] }); const [languages, setLanguages] = useState([]); const [uploadLanguage, setUploadLanguage] = useState("en"); const [uploading, setUploading] = useState(false); + const [zoom, setZoom] = useState(NO_ZOOM); const zoomRef = useRef(zoom); zoomRef.current = zoom; const zoomStart = useRef(undefined); + const [speedHold, setSpeedHold] = useState(false); const holdRate = useRef(1); + const [seekFlash, setSeekFlash] = useState<{ side: GestureSide; seconds: number; key: number } | undefined>(undefined); const seekFlashTimer = useRef(undefined); + const cast = usePlayerCast(video, media, setNotice, (seconds, resumePlaying) => { + const element = video.current; if (!element) return; + element.currentTime = seconds; setCurrentTime(seconds); + if (resumePlaying) safePlay(element); + }); const failPlayback = (message: string) => { setPlaybackError(message); setWaiting(false); setPlaying(false); video.current?.pause(); }; - const resumeAudioBoost = () => { - const value = selectedBoost.current; const output = audioBoost.current; - void output?.setBoost(value).then((enabled) => { - if (audioBoost.current !== output || enabled || selectedBoost.current !== value || value === 1) return; - selectedBoost.current = 1; setBoost(1); savePlayerAudioBoost(1); - void audioBoost.current?.setBoost(1); - setNotice("Audio boost is unavailable in this browser. Standard volume is still available."); - }); - }; - const changeBoost = (value: number) => { - selectedBoost.current = value; setBoost(value); savePlayerAudioBoost(value); resumeAudioBoost(); - }; const safePlay = (element: HTMLVideoElement) => { - resumeAudioBoost(); void element.play().catch((reason: unknown) => { if (reason instanceof DOMException && (reason.name === "AbortError" || reason.name === "NotAllowedError")) { setWaiting(false); return; } failPlayback("This video could not be played. Try again or check the file format."); @@ -97,9 +91,63 @@ export function PlayerViewer({ media, context, autoStart = false, close, favorit try { if (await remove(media)) return; } catch { /* The app-level notice reports request failures. */ } setDeleting(false); }; - const togglePlayback = () => { const element = video.current; if (!element) return; if (element.paused) safePlay(element); else element.pause(); }; - const seek = (value: number) => { const element = video.current; if (!element) return; element.currentTime = Math.max(0, Math.min(element.duration || 0, value)); setCurrentTime(element.currentTime); reveal(); }; - const toggleMute = () => { const element = video.current; if (!element) return; resumeAudioBoost(); element.muted = !element.muted; setMuted(element.muted); savePlayerAudio({ volume: element.volume, muted: element.muted }); }; + const togglePlayback = () => { if (cast.casting) { cast.togglePlay(); return; } const element = video.current; if (!element) return; if (element.paused) safePlay(element); else element.pause(); }; + const seek = (value: number) => { if (cast.casting) { cast.seek(value); reveal(); return; } const element = video.current; if (!element) return; element.currentTime = Math.max(0, Math.min(element.duration || 0, value)); setCurrentTime(element.currentTime); reveal(); }; + const shownTime = cast.casting ? cast.remoteTime : currentTime; + const shownDuration = cast.casting ? cast.remoteDuration || duration : duration; + const shownPlaying = cast.casting ? !cast.remotePaused : playing; + + // Touch gestures on the video surface (see player-gestures.ts). The latest handlers are + // read through a ref so the recognizer is created only once. + const surfaceSize = () => { const rect = surface.current?.getBoundingClientRect(); return { width: rect?.width ?? 0, height: rect?.height ?? 0 }; }; + const gesture = useRef({ + tap: (_pointerType: string) => {}, doubleTap: (_side: GestureSide, _pointerType: string) => {}, holdStart: () => {}, holdEnd: () => {}, + pinch: (_scale: number, _x: number, _y: number, _sx: number, _sy: number) => {}, pinchEnd: () => {}, pan: (_dx: number, _dy: number) => {}, panEnd: () => {}, + }); + gesture.current = { + tap: (pointerType) => { + if (pointerType === "mouse") { togglePlayback(); return; } + if (controls && shownPlaying) { autoHide.current?.cancel(); setControls(false); } else reveal(); + }, + doubleTap: (side, pointerType) => { + if (pointerType === "mouse") { void toggleFullscreen(); return; } + const step = side === "right" ? SEEK_STEP_SECONDS : -SEEK_STEP_SECONDS; + seek(shownTime + step); + window.clearTimeout(seekFlashTimer.current); + setSeekFlash((flash) => ({ side, seconds: flash && flash.side === side ? flash.seconds + SEEK_STEP_SECONDS : SEEK_STEP_SECONDS, key: (flash?.key ?? 0) + 1 })); + seekFlashTimer.current = window.setTimeout(() => setSeekFlash(undefined), 700); + }, + holdStart: () => { + const element = video.current; if (!element || cast.casting) return; + holdRate.current = element.playbackRate || 1; element.playbackRate = HOLD_PLAYBACK_RATE; setSpeedHold(true); + if (element.paused) safePlay(element); + }, + holdEnd: () => { const element = video.current; if (element) element.playbackRate = holdRate.current; setSpeedHold(false); }, + pinch: (scale, x, y, startX, startY) => { + zoomStart.current ??= zoomRef.current; + const { width, height } = surfaceSize(); + setZoom(pinchZoom(zoomStart.current, scale, x, y, startX, startY, width, height)); + }, + pinchEnd: () => { zoomStart.current = undefined; setZoom((value) => value.scale < 1.05 ? NO_ZOOM : value); }, + pan: (dx, dy) => { const { width, height } = surfaceSize(); setZoom((value) => clampZoom({ ...value, x: value.x + dx, y: value.y + dy }, width, height)); }, + panEnd: () => {}, + }; + const recognizer = useRef>(undefined); + recognizer.current ??= createPlayerGestures({ + width: () => surfaceSize().width, + zoomed: () => zoomRef.current.scale > 1, + actions: { + tap: (pointerType) => gesture.current.tap(pointerType), doubleTap: (side, pointerType) => gesture.current.doubleTap(side, pointerType), + holdStart: () => gesture.current.holdStart(), holdEnd: () => gesture.current.holdEnd(), + pinch: (scale, x, y, sx, sy) => gesture.current.pinch(scale, x, y, sx, sy), pinchEnd: () => gesture.current.pinchEnd(), + pan: (dx, dy) => gesture.current.pan(dx, dy), panEnd: () => gesture.current.panEnd(), + }, + }); + const gesturePoint = (event: ReactPointerEvent): GesturePoint => { + const rect = event.currentTarget.getBoundingClientRect(); + return { id: event.pointerId, x: event.clientX - rect.left, y: event.clientY - rect.top, pointerType: event.pointerType || "mouse", time: event.timeStamp || performance.now() }; + }; + const toggleMute = () => { const element = video.current; if (!element) return; element.muted = !element.muted; setMuted(element.muted); savePlayerAudio({ volume: element.volume, muted: element.muted }); }; const selectTrack = (id: string) => { setSubtitleTrack(id); localStorage.setItem("open-easyx.subtitle-track", id); setCaptionMenu(false); }; const toggleAutoplay = () => { const value = !autoplay; setAutoplay(value); localStorage.setItem("open-easyx.autoplay", String(value)); }; const next = async () => { @@ -115,12 +163,6 @@ export function PlayerViewer({ media, context, autoStart = false, close, favorit useEffect(() => { if (media.kind === "image") void api(`/api/media/${media.id}/progress`, { method: "PUT", body: JSON.stringify({ position: 0, duration: 0, completed: true }) }).catch(() => {}); }, [media.id, media.kind]); - useEffect(() => { - const element = video.current; if (media.kind !== "video" || !element) return; - const output = createPlayerAudioBoost(element); audioBoost.current = output; - resumeAudioBoost(); - return () => { audioBoost.current = undefined; output.dispose(); }; - }, [media.kind]); useEffect(() => { lastSaved.current = 0; autoHide.current?.cancel(); recoveryPosition.current = undefined; setPlaybackError(""); @@ -129,7 +171,7 @@ export function PlayerViewer({ media, context, autoStart = false, close, favorit } initialAudio.current = loadPlayerAudio(); setVolume(initialAudio.current.volume); setMuted(initialAudio.current.muted); setPlaying(false); setWaiting(false); setControls(true); setCurrentTime(media.progressSeconds || 0); setDuration(media.duration || 0); setBuffered(0); - setPhotoRemaining(PHOTO_AUTOPLAY_SECONDS); setPhotoReady(false); setCaptionMenu(false); + setPhotoRemaining(PHOTO_AUTOPLAY_SECONDS); setPhotoReady(false); setCaptionMenu(false); setZoom(NO_ZOOM); setSpeedHold(false); setSeekFlash(undefined); setSubtitles({ status: "disabled", progress: 0, sourceLanguage: "", error: "", tracks: [] }); }, [media.id]); useEffect(() => { @@ -173,14 +215,14 @@ export function PlayerViewer({ media, context, autoStart = false, close, favorit if (media.kind !== "video" || ["INPUT", "SELECT", "BUTTON"].includes((event.target as HTMLElement).tagName)) return; reveal(); if (event.code === "Space" || event.key.toLowerCase() === "k") { event.preventDefault(); togglePlayback(); } - else if (event.key === "ArrowLeft") seek(currentTime - 10); else if (event.key === "ArrowRight") seek(currentTime + 10); + else if (event.key === "ArrowLeft") seek(shownTime - 10); else if (event.key === "ArrowRight") seek(shownTime + 10); else if (event.key.toLowerCase() === "m") toggleMute(); else if (event.key.toLowerCase() === "f") void toggleFullscreen(); }; window.addEventListener("keydown", key); return () => window.removeEventListener("keydown", key); - }, [captionMenu, currentTime, media.id, media.kind, fullscreen, pageFullscreen]); + }, [captionMenu, currentTime, media.id, media.kind, fullscreen, pageFullscreen, cast.casting, cast.remoteTime]); // Only clear the auto-hide timer on unmount. Clearing it whenever the effect above re-runs (on every // timeupdate) kept the controls and progress bar visible for the whole video in fullscreen. - useEffect(() => () => autoHide.current?.cancel(), []); + useEffect(() => () => { autoHide.current?.cancel(); recognizer.current?.dispose(); window.clearTimeout(seekFlashTimer.current); }, []); useEffect(() => { if (!captionMenu) reveal(); }, [captionMenu]); useEffect(() => { reveal(); }, [fullscreen]); @@ -195,24 +237,31 @@ export function PlayerViewer({ media, context, autoStart = false, close, favorit }; const subtitleText = subtitles.status === "running" ? `Generating · ${Math.round(subtitles.progress)}%` : subtitles.status === "queued" ? "Waiting in the local queue" : subtitles.status === "error" ? subtitles.error || "Subtitle generation failed" : subtitles.status === "no_audio" ? "No audio track detected" : subtitles.status === "no_speech" ? "No speech detected" : subtitles.status === "disabled" ? "Enable automatic subtitles in Settings" : "No subtitle track yet"; - const progress = duration ? Math.min(100, currentTime / duration * 100) : 0; const bufferedProgress = duration ? Math.min(100, buffered / duration * 100) : 0; + const progress = shownDuration ? Math.min(100, shownTime / shownDuration * 100) : 0; const bufferedProgress = duration && !cast.casting ? Math.min(100, buffered / duration * 100) : 0; return
-
{media.kind === "video" ?
playing && !captionMenu && setControls(false)}> -
void toggleFullscreen()}>