Address the first beta's bugs and requested changes
Startup now uses the Android iris animation, and playback can continue in a corner miniplayer while browsing (the video is drawn into a corner rectangle beneath a matching hole in the page). The player keeps the window controls, hides its chrome when the pointer leaves, and gains audio/subtitle tracks, audio sync, source bitrate and playback details in its options. Subtitles can be styled in Settings with a live preview. Categories replace Collections, the A–Z rail magnifies, descriptions expand in place, downloads can be removed in bulk, and search keeps its results while typing. Fixes scroll jank from per-card and scrolling backdrop blurs, the hidden colour wash, the cubic volume curve, loud theme music, the search focus ring, a stray nav indicator, Continue Watching previews and the TV Shows header overlap. Removes the star rating, the duplicate Settings menu entry and the server settings' Show advanced switch. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
be865fa992
commit
43c168da95
35 changed files with 1771 additions and 327 deletions
|
|
@ -1,30 +1,51 @@
|
|||
import { useCallback, useEffect, useRef, useState, type ReactNode } from 'react';
|
||||
import { usePlayer } from './store';
|
||||
import { useSession } from '../app/session';
|
||||
import { useSettings, QUALITY_LABEL, type Quality } from '../app/settings';
|
||||
import { clock, episodeLabel } from '../app/format';
|
||||
import { useSettings, QUALITY_LABEL, type Quality, type SubtitleBox } from '../app/settings';
|
||||
import { bitrate, channelLabel, clock, episodeLabel, resolutionLabel } from '../app/format';
|
||||
import { Icon } from '../ui/Icon';
|
||||
import { Facts, TitleArt } from '../ui/media';
|
||||
import { Button, Spinner } from '../ui/primitives';
|
||||
import { win, isNative } from '../platform/native';
|
||||
import { WindowControls } from '../app/TopBar';
|
||||
import { mpv } from './engine';
|
||||
import type { Item } from '../plex/types';
|
||||
|
||||
const HIDE_AFTER = 3000;
|
||||
|
||||
/**
|
||||
* Controls show on pointer movement and hide after a few seconds of stillness,
|
||||
* or straight away when the pointer leaves the window. They stay while paused
|
||||
* (until the pointer leaves) and while a panel is open or the timeline is held.
|
||||
*/
|
||||
function useAutoHide(paused: boolean, pinned: boolean) {
|
||||
const [visible, setVisible] = useState(true);
|
||||
const timer = useRef<ReturnType<typeof setTimeout> | null>(null);
|
||||
const state = useRef({ paused, pinned });
|
||||
state.current = { paused, pinned };
|
||||
const poke = useCallback(() => {
|
||||
setVisible(true);
|
||||
if (timer.current) clearTimeout(timer.current);
|
||||
timer.current = setTimeout(() => setVisible(false), HIDE_AFTER);
|
||||
timer.current = null;
|
||||
if (!state.current.paused && !state.current.pinned) timer.current = setTimeout(() => setVisible(false), HIDE_AFTER);
|
||||
}, []);
|
||||
useEffect(() => {
|
||||
if (paused || pinned) {
|
||||
if (timer.current) clearTimeout(timer.current);
|
||||
setVisible(true);
|
||||
} else poke();
|
||||
poke();
|
||||
}, [paused, pinned, poke]);
|
||||
useEffect(() => {
|
||||
const leave = () => {
|
||||
if (state.current.pinned) return;
|
||||
if (timer.current) clearTimeout(timer.current);
|
||||
timer.current = null;
|
||||
setVisible(false);
|
||||
};
|
||||
const root = document.documentElement;
|
||||
root.addEventListener('mouseleave', leave);
|
||||
return () => {
|
||||
root.removeEventListener('mouseleave', leave);
|
||||
if (timer.current) clearTimeout(timer.current);
|
||||
};
|
||||
}, []);
|
||||
return { visible, poke };
|
||||
}
|
||||
|
||||
|
|
@ -123,20 +144,27 @@ function Timeline({ onScrub }: { onScrub: (active: boolean) => void }) {
|
|||
);
|
||||
}
|
||||
|
||||
function Panel({ title, onClose, children, className = '' }: { title: string; onClose: () => void; children: ReactNode; className?: string }) {
|
||||
function Panel({ title, onClose, onBack, children, className = '' }: { title: string; onClose: () => void; onBack?: () => void; children: ReactNode; className?: string }) {
|
||||
useEffect(() => {
|
||||
const onKey = (e: KeyboardEvent) => {
|
||||
if (e.key === 'Escape') {
|
||||
e.stopPropagation();
|
||||
onClose();
|
||||
(onBack ?? onClose)();
|
||||
}
|
||||
};
|
||||
window.addEventListener('keydown', onKey, true);
|
||||
return () => window.removeEventListener('keydown', onKey, true);
|
||||
}, [onClose]);
|
||||
}, [onClose, onBack]);
|
||||
return (
|
||||
<div className={`player-panel ${className}`} onClick={(e) => e.stopPropagation()} onDoubleClick={(e) => e.stopPropagation()}>
|
||||
<div className="player-panel-title">{title}</div>
|
||||
<div className="player-panel-title">
|
||||
{onBack && (
|
||||
<button className="panel-back" onClick={onBack} aria-label="Back">
|
||||
<Icon name="back" size={15} />
|
||||
</button>
|
||||
)}
|
||||
{title}
|
||||
</div>
|
||||
{children}
|
||||
</div>
|
||||
);
|
||||
|
|
@ -172,58 +200,145 @@ function TracksPanel({ onClose }: { onClose: () => void }) {
|
|||
{st.subTracks.map((t) => (
|
||||
<Option key={t.key} selected={t.key === st.subKey} label={t.label} detail={t.detail} onClick={() => st.selectSubtitle(t.key)} />
|
||||
))}
|
||||
{st.subKey && st.delivery?.mode !== 'transcode' && (
|
||||
<div className="panel-delay">
|
||||
<span>Timing</span>
|
||||
<button onClick={() => st.setSubDelay(st.subDelay - 0.1)}>−</button>
|
||||
<b>{st.subDelay > 0 ? '+' : ''}{st.subDelay.toFixed(1)}s</b>
|
||||
<button onClick={() => st.setSubDelay(st.subDelay + 0.1)}>+</button>
|
||||
</div>
|
||||
)}
|
||||
{st.subKey && st.delivery?.mode !== 'transcode' && <Stepper label="Timing" value={st.subDelay} onChange={st.setSubDelay} />}
|
||||
</div>
|
||||
</div>
|
||||
</Panel>
|
||||
);
|
||||
}
|
||||
|
||||
function Stepper({ label, value, onChange }: { label: string; value: number; onChange: (v: number) => void }) {
|
||||
return (
|
||||
<div className="panel-delay">
|
||||
<span>{label}</span>
|
||||
<button onClick={() => onChange(Math.round((value - 0.1) * 10) / 10)} aria-label={`${label} earlier`}>
|
||||
−
|
||||
</button>
|
||||
<b>
|
||||
{value > 0 ? '+' : ''}
|
||||
{value.toFixed(1)}s
|
||||
</b>
|
||||
<button onClick={() => onChange(Math.round((value + 0.1) * 10) / 10)} aria-label={`${label} later`}>
|
||||
+
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const SUB_SIZES = [
|
||||
{ value: 0.8, label: 'Small' },
|
||||
{ value: 1, label: 'Normal' },
|
||||
{ value: 1.25, label: 'Large' },
|
||||
{ value: 1.5, label: 'Extra large' },
|
||||
];
|
||||
const SUB_BOXES: { value: SubtitleBox; label: string }[] = [
|
||||
{ value: 'none', label: 'None' },
|
||||
{ value: 'translucent', label: 'Translucent' },
|
||||
{ value: 'solid', label: 'Solid' },
|
||||
];
|
||||
|
||||
type SettingsView = 'main' | 'audio' | 'subtitles' | 'quality' | 'speed' | 'version' | 'chapters' | 'subSize' | 'subBox';
|
||||
|
||||
function SettingsPanel({ onClose }: { onClose: () => void }) {
|
||||
const st = usePlayer();
|
||||
const [view, setView] = useState<'main' | 'quality' | 'speed' | 'version' | 'chapters'>('main');
|
||||
const speeds = [0.5, 0.75, 1, 1.25, 1.5, 2];
|
||||
const prefs = useSettings();
|
||||
const [view, setView] = useState<SettingsView>('main');
|
||||
const speeds = [0.5, 0.75, 1, 1.25, 1.5, 1.75, 2];
|
||||
const media = st.item?.media ?? [];
|
||||
const source = media[st.mediaIndex];
|
||||
const local = st.delivery?.mode === 'local';
|
||||
const back = () => setView('main');
|
||||
const audio = st.audioTracks.find((t) => t.key === st.audioKey);
|
||||
const sub = st.subTracks.find((t) => t.key === st.subKey);
|
||||
const qualityLabel = (q: Quality) => (q === 'original' ? `Original${source?.bitrate ? ` · ${bitrate(source.bitrate)}` : ''}` : QUALITY_LABEL[q]);
|
||||
|
||||
if (view === 'audio')
|
||||
return (
|
||||
<Panel title="Audio" onClose={onClose} onBack={back}>
|
||||
{st.audioTracks.map((t) => (
|
||||
<Option key={t.key} selected={t.key === st.audioKey} label={t.label} detail={t.detail} onClick={() => (st.selectAudio(t.key), back())} />
|
||||
))}
|
||||
{!st.audioTracks.length && <div className="panel-empty">No audio tracks</div>}
|
||||
{st.delivery?.mode !== 'transcode' && <Stepper label="Audio sync" value={st.audioDelay} onChange={st.setAudioDelay} />}
|
||||
</Panel>
|
||||
);
|
||||
if (view === 'subtitles')
|
||||
return (
|
||||
<Panel title="Subtitles" onClose={onClose} onBack={back}>
|
||||
<Option selected={!st.subKey} label="Off" onClick={() => (st.selectSubtitle(''), back())} />
|
||||
{st.subTracks.map((t) => (
|
||||
<Option key={t.key} selected={t.key === st.subKey} label={t.label} detail={t.detail} onClick={() => (st.selectSubtitle(t.key), back())} />
|
||||
))}
|
||||
{st.subKey && st.delivery?.mode !== 'transcode' && <Stepper label="Subtitle timing" value={st.subDelay} onChange={st.setSubDelay} />}
|
||||
</Panel>
|
||||
);
|
||||
if (view === 'quality')
|
||||
return (
|
||||
<Panel title="Quality" onClose={onClose}>
|
||||
<Panel title="Quality" onClose={onClose} onBack={back}>
|
||||
{(Object.keys(QUALITY_LABEL) as Quality[]).map((q) => (
|
||||
<Option key={q} selected={st.quality === q} label={QUALITY_LABEL[q]} detail={q === 'original' ? 'Direct play of the source file' : 'Converted by your Plex server'} onClick={() => (st.setQuality(q), onClose())} />
|
||||
<Option
|
||||
key={q}
|
||||
selected={st.quality === q}
|
||||
label={qualityLabel(q)}
|
||||
detail={q === 'original' ? [resolutionLabel(source), source?.videoCodec.toUpperCase(), 'Direct play of the source file'].filter(Boolean).join(' · ') : 'Converted by your Plex server'}
|
||||
onClick={() => (st.setQuality(q), onClose())}
|
||||
/>
|
||||
))}
|
||||
</Panel>
|
||||
);
|
||||
if (view === 'speed')
|
||||
return (
|
||||
<Panel title="Playback speed" onClose={onClose}>
|
||||
<Panel title="Playback speed" onClose={onClose} onBack={back}>
|
||||
{speeds.map((s) => (
|
||||
<Option key={s} selected={Math.abs(st.speed - s) < 0.01} label={s === 1 ? 'Normal' : `${s}×`} onClick={() => (st.setSpeed(s), onClose())} />
|
||||
<Option key={s} selected={Math.abs(st.speed - s) < 0.01} label={s === 1 ? 'Normal' : `${s}×`} onClick={() => (st.setSpeed(s), back())} />
|
||||
))}
|
||||
</Panel>
|
||||
);
|
||||
if (view === 'version')
|
||||
return (
|
||||
<Panel title="Version" onClose={onClose}>
|
||||
<Panel title="Version" onClose={onClose} onBack={back}>
|
||||
{media.map((m, i) => (
|
||||
<Option key={m.id} selected={st.mediaIndex === i} label={m.title || `${m.videoResolution.toUpperCase()} ${m.videoCodec.toUpperCase()}`} detail={[m.container.toUpperCase(), m.bitrate ? `${Math.round(m.bitrate / 1000)} Mbps` : ''].filter(Boolean).join(' · ')} onClick={() => (st.selectVersion(i), onClose())} />
|
||||
<Option
|
||||
key={m.id}
|
||||
selected={st.mediaIndex === i}
|
||||
label={m.title || [resolutionLabel(m), m.videoCodec.toUpperCase()].filter(Boolean).join(' ')}
|
||||
detail={[m.container.toUpperCase(), bitrate(m.bitrate), [m.audioCodec.toUpperCase(), channelLabel(m.audioChannels)].filter(Boolean).join(' ')].filter(Boolean).join(' · ')}
|
||||
onClick={() => (st.selectVersion(i), onClose())}
|
||||
/>
|
||||
))}
|
||||
</Panel>
|
||||
);
|
||||
if (view === 'chapters')
|
||||
return (
|
||||
<Panel title="Chapters" onClose={onClose} className="chapters">
|
||||
{st.chapters.map((c) => (
|
||||
<Option key={c.time} selected={false} label={c.title} detail={clock(c.time)} onClick={() => (st.seek(c.time), onClose())} />
|
||||
<Panel title="Chapters" onClose={onClose} onBack={back} className="chapters">
|
||||
{st.chapters.map((c, i) => (
|
||||
<Option
|
||||
key={c.time}
|
||||
selected={st.position >= c.time && st.position < (st.chapters[i + 1]?.time ?? Infinity)}
|
||||
label={c.title}
|
||||
detail={clock(c.time)}
|
||||
onClick={() => (st.seek(c.time), onClose())}
|
||||
/>
|
||||
))}
|
||||
</Panel>
|
||||
);
|
||||
if (view === 'subSize')
|
||||
return (
|
||||
<Panel title="Subtitle size" onClose={onClose} onBack={back}>
|
||||
{SUB_SIZES.map((o) => (
|
||||
<Option key={o.value} selected={prefs.subtitleScale === o.value} label={o.label} onClick={() => (prefs.set('subtitleScale', o.value), back())} />
|
||||
))}
|
||||
</Panel>
|
||||
);
|
||||
if (view === 'subBox')
|
||||
return (
|
||||
<Panel title="Subtitle background" onClose={onClose} onBack={back}>
|
||||
{SUB_BOXES.map((o) => (
|
||||
<Option key={o.value} selected={prefs.subtitleBox === o.value} label={o.label} onClick={() => (prefs.set('subtitleBox', o.value), back())} />
|
||||
))}
|
||||
</Panel>
|
||||
);
|
||||
|
||||
const row = (label: string, value: string, go: () => void, disabled = false) => (
|
||||
<button className="panel-row" onClick={go} disabled={disabled}>
|
||||
<span>{label}</span>
|
||||
|
|
@ -231,19 +346,33 @@ function SettingsPanel({ onClose }: { onClose: () => void }) {
|
|||
<Icon name="next" size={14} />
|
||||
</button>
|
||||
);
|
||||
const v = st.video;
|
||||
const stats: [string, string][] = [
|
||||
['Playback', st.delivery?.mode === 'direct' ? 'Direct play' : st.delivery?.mode === 'transcode' ? `Converting to ${QUALITY_LABEL[st.quality]}` : local ? 'Downloaded file' : ''],
|
||||
];
|
||||
if (v && v.width > 0)
|
||||
stats.push(['Video', [`${v.width}×${v.height}`, v.codec.toUpperCase(), source?.dynamicRange, v.hwdec && v.hwdec !== 'no' ? 'Hardware decoding' : 'Software decoding'].filter(Boolean).join(' · ')]);
|
||||
if (audio) stats.push(['Audio', [audio.label, audio.detail].filter(Boolean).join(' · ')]);
|
||||
if (source?.bitrate && !local) stats.push(['Bitrate', st.delivery?.mode === 'transcode' ? `${bitrate(source.bitrate)} source` : bitrate(source.bitrate)]);
|
||||
if (source?.container) stats.push(['Container', source.container.toUpperCase()]);
|
||||
|
||||
return (
|
||||
<Panel title="Playback" onClose={onClose}>
|
||||
{!local && row('Quality', QUALITY_LABEL[st.quality], () => setView('quality'))}
|
||||
{row('Audio', audio ? audio.label : st.audioTracks.length ? 'Choose' : 'None', () => setView('audio'), !st.audioTracks.length)}
|
||||
{row('Subtitles', sub ? sub.label : 'Off', () => setView('subtitles'))}
|
||||
{!local && row('Quality', qualityLabel(st.quality), () => setView('quality'))}
|
||||
{row('Speed', st.speed === 1 ? 'Normal' : `${st.speed}×`, () => setView('speed'))}
|
||||
{media.length > 1 && !local && row('Version', `${st.mediaIndex + 1} of ${media.length}`, () => setView('version'))}
|
||||
{st.chapters.length > 1 && row('Chapters', `${st.chapters.length}`, () => setView('chapters'))}
|
||||
<div className="panel-info">
|
||||
{st.delivery?.mode === 'direct' && 'Direct play'}
|
||||
{st.delivery?.mode === 'transcode' && `Converting to ${st.delivery.label}`}
|
||||
{st.delivery?.mode === 'local' && 'Playing from this computer'}
|
||||
{st.video && st.video.width > 0 && ` · ${st.video.width}×${st.video.height}`}
|
||||
{st.video?.codec && ` · ${st.video.codec.toUpperCase()}`}
|
||||
{st.video?.hwdec && st.video.hwdec !== 'no' ? ' · Hardware decoding' : ''}
|
||||
{row('Subtitle size', SUB_SIZES.find((o) => o.value === prefs.subtitleScale)?.label ?? 'Custom', () => setView('subSize'))}
|
||||
{row('Subtitle background', SUB_BOXES.find((o) => o.value === prefs.subtitleBox)?.label ?? '', () => setView('subBox'))}
|
||||
<div className="panel-stats">
|
||||
{stats.map(([k, val]) => (
|
||||
<div key={k}>
|
||||
<span>{k}</span>
|
||||
<b>{val}</b>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</Panel>
|
||||
);
|
||||
|
|
@ -350,6 +479,93 @@ function TitleBlock({ item }: { item: Item }) {
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Playing in the corner while browsing. The native video is drawn into this
|
||||
* box's rectangle and the page has a matching hole (see `html.player-mini`).
|
||||
*/
|
||||
function MiniPlayer() {
|
||||
const st = usePlayer();
|
||||
const box = useRef<HTMLDivElement>(null);
|
||||
|
||||
useEffect(() => {
|
||||
const el = box.current;
|
||||
if (!el) return;
|
||||
let frame = 0;
|
||||
const place = () => {
|
||||
cancelAnimationFrame(frame);
|
||||
frame = requestAnimationFrame(() => {
|
||||
// The layout box, not getBoundingClientRect: transforms (an entrance
|
||||
// animation) must not move the video away from the page's hole.
|
||||
const cs = getComputedStyle(el);
|
||||
const width = parseFloat(cs.width);
|
||||
const height = parseFloat(cs.height);
|
||||
const x = window.innerWidth - parseFloat(cs.right) - width;
|
||||
const y = window.innerHeight - parseFloat(cs.bottom) - height;
|
||||
const dpr = window.devicePixelRatio || 1;
|
||||
// A pixel of overdraw on each side keeps the hole covered at any scale.
|
||||
if (isNative) mpv.rect({ x: x * dpr - 1, y: y * dpr - 1, width: width * dpr + 2, height: height * dpr + 2 }).catch(() => {});
|
||||
});
|
||||
};
|
||||
place();
|
||||
const ro = new ResizeObserver(place);
|
||||
ro.observe(el);
|
||||
window.addEventListener('resize', place);
|
||||
return () => {
|
||||
cancelAnimationFrame(frame);
|
||||
ro.disconnect();
|
||||
window.removeEventListener('resize', place);
|
||||
};
|
||||
}, []);
|
||||
|
||||
if (!st.item) return null;
|
||||
const item = st.item;
|
||||
const loading = !st.firstFrame && !st.error;
|
||||
const pct = st.duration ? Math.min(100, (st.position / st.duration) * 100) : 0;
|
||||
return (
|
||||
<div ref={box} className={`mini-player${loading || st.error ? ' loading' : ''}`} onDoubleClick={() => st.expand()}>
|
||||
<div className="mini-scrim" />
|
||||
<div className="mini-top">
|
||||
<button className="mini-icon" aria-label="Back to full screen player" title="Expand" onClick={() => st.expand()}>
|
||||
<Icon name="expand" size={17} />
|
||||
</button>
|
||||
<button className="mini-icon" aria-label="Stop playback" title="Close" onClick={() => st.close()}>
|
||||
<Icon name="x" size={18} />
|
||||
</button>
|
||||
</div>
|
||||
<div className="mini-center">
|
||||
{(loading || st.buffering) && !st.error ? (
|
||||
<Spinner size={30} />
|
||||
) : st.error ? (
|
||||
<span className="mini-error">Playback stopped</span>
|
||||
) : (
|
||||
<>
|
||||
<button className="mini-icon" aria-label="Back 10 seconds" onClick={() => st.seekBy(-10)}>
|
||||
<Icon name="replay10" size={22} />
|
||||
</button>
|
||||
<button className="mini-icon big" aria-label={st.paused ? 'Play' : 'Pause'} onClick={() => st.togglePause()}>
|
||||
<Icon name={st.paused || st.ended ? 'play' : 'pause'} size={26} />
|
||||
</button>
|
||||
<button className="mini-icon" aria-label="Forward 10 seconds" onClick={() => st.seekBy(10)}>
|
||||
<Icon name="forward10" size={22} />
|
||||
</button>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
<div className="mini-caption">
|
||||
<b>{item.type === 'episode' ? item.grandparentTitle : item.title}</b>
|
||||
{item.type === 'episode' && (
|
||||
<span>
|
||||
{episodeLabel(item)} · {item.title}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
<div className="mini-progress">
|
||||
<i style={{ width: `${pct}%` }} />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function PlayerOverlay() {
|
||||
const st = usePlayer();
|
||||
const server = useSession((s) => s.server);
|
||||
|
|
@ -363,11 +579,11 @@ export function PlayerOverlay() {
|
|||
const showFlash = (icon: string) => setFlash({ icon, key: Date.now() });
|
||||
|
||||
useEffect(() => {
|
||||
if (!st.open) setPanel('');
|
||||
}, [st.open]);
|
||||
if (!st.open || st.mini) setPanel('');
|
||||
}, [st.open, st.mini]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!st.open) return;
|
||||
if (!st.open || st.mini) return;
|
||||
const onKey = async (e: KeyboardEvent) => {
|
||||
if ((e.target as HTMLElement)?.tagName === 'INPUT' && (e.target as HTMLInputElement).type !== 'range') return;
|
||||
const p = usePlayer.getState();
|
||||
|
|
@ -421,11 +637,11 @@ export function PlayerOverlay() {
|
|||
case 'Escape': {
|
||||
const fs = await win.isFullscreen().catch(() => false);
|
||||
if (fs) p.toggleFullscreen();
|
||||
else p.close();
|
||||
else p.minimize();
|
||||
break;
|
||||
}
|
||||
case 'Backspace':
|
||||
p.close();
|
||||
p.minimize();
|
||||
break;
|
||||
case 'Home':
|
||||
p.seek(0);
|
||||
|
|
@ -442,9 +658,10 @@ export function PlayerOverlay() {
|
|||
};
|
||||
window.addEventListener('keydown', onKey);
|
||||
return () => window.removeEventListener('keydown', onKey);
|
||||
}, [st.open, seekStep, poke]);
|
||||
}, [st.open, st.mini, seekStep, poke]);
|
||||
|
||||
if (!st.open || !st.item) return null;
|
||||
if (st.mini) return <MiniPlayer />;
|
||||
const item = st.item;
|
||||
const loading = !st.firstFrame && !st.error;
|
||||
const art = item.type === 'episode' ? item.grandparentArt || item.art : item.art;
|
||||
|
|
@ -482,9 +699,10 @@ export function PlayerOverlay() {
|
|||
<div className="player-gradient bottom" />
|
||||
|
||||
<div className="player-top" data-tauri-drag-region={isNative ? true : undefined} onClick={(e) => e.stopPropagation()} onDoubleClick={(e) => e.stopPropagation()}>
|
||||
<button className="player-back" onClick={() => st.close()} aria-label="Back">
|
||||
<button className="player-back" onClick={() => st.minimize()} aria-label="Back to browsing" title="Keep playing in the corner">
|
||||
<Icon name="arrowLeft" size={22} />
|
||||
</button>
|
||||
{!st.fullscreen && <WindowControls />}
|
||||
</div>
|
||||
|
||||
{(loading || st.buffering || st.seeking) && !st.error && (
|
||||
|
|
|
|||
|
|
@ -39,5 +39,7 @@ export const mpv = {
|
|||
set: (name: string, value: unknown) => invoke<void>('player_set', { name, value }),
|
||||
get: <T = any>(name: string) => invoke<T>('player_get', { name }),
|
||||
show: (visible: boolean) => invoke<void>('player_show', { visible }),
|
||||
/** Draws the video in part of the window (physical pixels), or all of it with null. */
|
||||
rect: (rect: { x: number; y: number; width: number; height: number } | null) => invoke<void>('player_rect', { rect }),
|
||||
on: (handler: (e: MpvEvent) => void) => listen<MpvEvent>('mpv', handler),
|
||||
};
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import * as api from '../plex/api';
|
|||
import { directUrl, previewUrl, reportTimeline, stopTranscode, transcodeUrl, type Delivery } from '../plex/playback';
|
||||
import type { Item, Stream } from '../plex/types';
|
||||
import { useSession } from '../app/session';
|
||||
import { useSettings, type Quality } from '../app/settings';
|
||||
import { useSettings, SUBTITLE_MARGIN, type Preferences, type Quality } from '../app/settings';
|
||||
import { channelLabel } from '../app/format';
|
||||
import { invalidateLibrary } from '../app/queries';
|
||||
import { keepAwake, isNative, win } from '../platform/native';
|
||||
|
|
@ -61,6 +61,9 @@ interface PlayerState {
|
|||
countdown: number | null;
|
||||
postPlayDismissed: boolean;
|
||||
fullscreen: boolean;
|
||||
/** Playing in the corner while browsing. */
|
||||
mini: boolean;
|
||||
audioDelay: number;
|
||||
|
||||
play(item: Item, opts?: PlayOptions): Promise<void>;
|
||||
close(): Promise<void>;
|
||||
|
|
@ -71,6 +74,9 @@ interface PlayerState {
|
|||
toggleMute(): void;
|
||||
setSpeed(s: number): void;
|
||||
setSubDelay(s: number): void;
|
||||
setAudioDelay(s: number): void;
|
||||
minimize(): Promise<void>;
|
||||
expand(): void;
|
||||
selectAudio(key: string): Promise<void>;
|
||||
selectSubtitle(key: string): Promise<void>;
|
||||
setQuality(q: Quality): Promise<void>;
|
||||
|
|
@ -94,6 +100,14 @@ let pendingExternal: Track | null = null;
|
|||
|
||||
const server = () => useSession.getState().server;
|
||||
|
||||
/**
|
||||
* mpv applies its volume on a cubic curve, so halfway on a linear slider was
|
||||
* only an eighth of the amplitude. The slider follows a square law instead
|
||||
* (halfway is about -12 dB, close to how loud it sounds).
|
||||
*/
|
||||
export const sliderToMpv = (v: number) => 100 * Math.pow(Math.max(0, v) / 100, 2 / 3);
|
||||
const mpvToSlider = (v: number) => 100 * Math.pow(Math.max(0, v) / 100, 3 / 2);
|
||||
|
||||
function languageName(code: string, fallback: string) {
|
||||
if (!code) return fallback;
|
||||
try {
|
||||
|
|
@ -147,6 +161,48 @@ function mpvTrackLabel(t: MpvTrack): Track {
|
|||
};
|
||||
}
|
||||
|
||||
/** Sets the first property name this libmpv knows (some were renamed in 0.38). */
|
||||
async function setAny(names: string[], value: unknown) {
|
||||
for (const name of names) {
|
||||
try {
|
||||
await mpv.set(name, value);
|
||||
return true;
|
||||
} catch {
|
||||
/* try the older name */
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/** mpv colours are #AARRGGBB. */
|
||||
const mpvColor = (hex: string, alpha = 1) => `#${Math.round(alpha * 255).toString(16).padStart(2, '0')}${hex.replace('#', '')}`.toUpperCase();
|
||||
|
||||
/** Applies the text subtitle look from preferences (image subtitles keep their own). */
|
||||
async function applySubtitleStyle(prefs: Preferences = useSettings.getState()) {
|
||||
const edge = prefs.subtitleEdge;
|
||||
await mpv.set('sub-scale', prefs.subtitleScale).catch(() => {});
|
||||
await mpv.set('sub-color', mpvColor(prefs.subtitleColor)).catch(() => {});
|
||||
await mpv.set('sub-bold', prefs.subtitleBold).catch(() => {});
|
||||
await mpv.set('sub-margin-y', SUBTITLE_MARGIN[prefs.subtitlePosition]).catch(() => {});
|
||||
await setAny(['sub-outline-color', 'sub-border-color'], '#FF000000');
|
||||
await setAny(['sub-outline-size', 'sub-border-size'], edge === 'outline' ? 1.8 : edge === 'raised' ? 1.3 : 0);
|
||||
await mpv.set('sub-shadow-offset', edge === 'shadow' ? 2.2 : edge === 'raised' ? 1.6 : 0).catch(() => {});
|
||||
await mpv.set('sub-shadow-color', '#B4000000').catch(() => {});
|
||||
if (prefs.subtitleBox === 'none') {
|
||||
await mpv.set('sub-border-style', 'outline-and-shadow').catch(() => {});
|
||||
await mpv.set('sub-back-color', '#B4000000').catch(() => {});
|
||||
return;
|
||||
}
|
||||
const box = prefs.subtitleBox === 'solid' ? '#FF000000' : '#A0000000';
|
||||
await mpv.set('sub-back-color', box).catch(() => {});
|
||||
if (!(await setAny(['sub-border-style'], 'background-box'))) {
|
||||
// Before background-box, an opaque box is drawn in the outline colour.
|
||||
await mpv.set('sub-border-style', 'opaque-box').catch(() => {});
|
||||
await setAny(['sub-outline-color', 'sub-border-color'], box);
|
||||
await setAny(['sub-outline-size', 'sub-border-size'], 3);
|
||||
}
|
||||
}
|
||||
|
||||
function report(state: 'playing' | 'paused' | 'buffering' | 'stopped') {
|
||||
const s = server();
|
||||
const { item, position, delivery } = usePlayer.getState();
|
||||
|
|
@ -313,7 +369,7 @@ function onEvent(e: MpvEvent) {
|
|||
if (typeof v === 'number') usePlayer.setState({ cacheTime: v });
|
||||
break;
|
||||
case 'volume':
|
||||
if (typeof v === 'number') usePlayer.setState({ volume: v });
|
||||
if (typeof v === 'number') usePlayer.setState({ volume: Math.round(mpvToSlider(v)) });
|
||||
break;
|
||||
case 'mute':
|
||||
usePlayer.setState({ muted: !!v });
|
||||
|
|
@ -324,6 +380,9 @@ function onEvent(e: MpvEvent) {
|
|||
case 'sub-delay':
|
||||
if (typeof v === 'number') usePlayer.setState({ subDelay: v });
|
||||
break;
|
||||
case 'audio-delay':
|
||||
if (typeof v === 'number') usePlayer.setState({ audioDelay: v });
|
||||
break;
|
||||
case 'chapter-list':
|
||||
if (Array.isArray(v) && v.length > 1 && !st.chapters.length)
|
||||
usePlayer.setState({ chapters: v.map((c: any, i: number) => ({ title: c.title && !/^\d\d:\d\d/.test(c.title) ? c.title : `Chapter ${i + 1}`, time: c.time })) });
|
||||
|
|
@ -432,6 +491,8 @@ export const usePlayer = create<PlayerState>((set, get) => ({
|
|||
countdown: null,
|
||||
postPlayDismissed: false,
|
||||
fullscreen: false,
|
||||
mini: false,
|
||||
audioDelay: 0,
|
||||
|
||||
async play(input, opts = {}) {
|
||||
const token = ++loadToken;
|
||||
|
|
@ -473,8 +534,8 @@ export const usePlayer = create<PlayerState>((set, get) => ({
|
|||
subKey: '__init',
|
||||
video: null,
|
||||
fullscreen: wasFullscreenBeforePlay,
|
||||
mini: false,
|
||||
});
|
||||
document.documentElement.classList.add('player-open');
|
||||
|
||||
try {
|
||||
// Full metadata: streams, markers and chapters.
|
||||
|
|
@ -525,11 +586,10 @@ export const usePlayer = create<PlayerState>((set, get) => ({
|
|||
if (!unlisten) unlisten = await mpv.on(onEvent);
|
||||
if (token !== loadToken) return;
|
||||
await mpv.set('mute', false);
|
||||
await mpv.set('volume', prefs.volume);
|
||||
await mpv.set('volume', sliderToMpv(prefs.volume));
|
||||
await mpv.set('speed', 1);
|
||||
await mpv.set('sub-scale', prefs.subtitleScale);
|
||||
await mpv.set('sub-back-color', prefs.subtitleBackground ? '#C0000000' : '#00000000');
|
||||
await mpv.set('sub-border-style', prefs.subtitleBackground ? 'opaque-box' : 'outline-and-shadow');
|
||||
await mpv.set('audio-delay', 0);
|
||||
await applySubtitleStyle(prefs);
|
||||
await mpv.set('force-media-title', item.type === 'episode' ? `${item.grandparentTitle} — ${item.title}` : item.title);
|
||||
await mpv.show(true);
|
||||
const fileOpts = [
|
||||
|
|
@ -565,8 +625,7 @@ export const usePlayer = create<PlayerState>((set, get) => ({
|
|||
await mpv.command('stop').catch(() => {});
|
||||
await mpv.show(false).catch(() => {});
|
||||
}
|
||||
document.documentElement.classList.remove('player-open', 'video-active');
|
||||
set({ open: false, item: null, delivery: null, error: '', countdown: null, nextUp: null, firstFrame: false });
|
||||
set({ open: false, mini: false, item: null, delivery: null, error: '', countdown: null, nextUp: null, firstFrame: false });
|
||||
const fs = await win.isFullscreen().catch(() => false);
|
||||
if (fs && !wasFullscreenBeforePlay) win.setFullscreen(false);
|
||||
if (st.item) invalidateLibrary();
|
||||
|
|
@ -601,7 +660,7 @@ export const usePlayer = create<PlayerState>((set, get) => ({
|
|||
const volume = Math.max(0, Math.min(150, Math.round(v)));
|
||||
set({ volume });
|
||||
useSettings.getState().set('volume', Math.min(100, volume));
|
||||
mpv.set('volume', volume).catch(() => {});
|
||||
mpv.set('volume', sliderToMpv(volume)).catch(() => {});
|
||||
if (get().muted && volume > 0) mpv.set('mute', false).catch(() => {});
|
||||
},
|
||||
|
||||
|
|
@ -617,6 +676,27 @@ export const usePlayer = create<PlayerState>((set, get) => ({
|
|||
mpv.set('sub-delay', delay).catch(() => {});
|
||||
},
|
||||
|
||||
setAudioDelay(delay) {
|
||||
mpv.set('audio-delay', delay).catch(() => {});
|
||||
},
|
||||
|
||||
async minimize() {
|
||||
const st = get();
|
||||
if (!st.open || st.mini) return;
|
||||
set({ mini: true });
|
||||
// Full screen was for the video; browsing goes back to the window.
|
||||
if (st.fullscreen && !wasFullscreenBeforePlay) {
|
||||
await win.setFullscreen(false).catch(() => {});
|
||||
set({ fullscreen: false });
|
||||
}
|
||||
},
|
||||
|
||||
expand() {
|
||||
if (!get().mini) return;
|
||||
set({ mini: false });
|
||||
if (isNative) mpv.rect(null).catch(() => {});
|
||||
},
|
||||
|
||||
async selectAudio(key) {
|
||||
const st = get();
|
||||
const t = st.audioTracks.find((x) => x.key === key);
|
||||
|
|
@ -685,9 +765,21 @@ export const usePlayer = create<PlayerState>((set, get) => ({
|
|||
},
|
||||
}));
|
||||
|
||||
/** Shown once the first frame is ready, the page turns transparent over the video. */
|
||||
/**
|
||||
* Shown once the first frame is ready, the page turns transparent over the
|
||||
* video. In the miniplayer the interface stays, with a hole for the video.
|
||||
*/
|
||||
usePlayer.subscribe((st, prev) => {
|
||||
if (st.firstFrame !== prev.firstFrame || st.open !== prev.open || st.error !== prev.error) {
|
||||
document.documentElement.classList.toggle('video-active', st.open && st.firstFrame && !st.error);
|
||||
if (st.firstFrame !== prev.firstFrame || st.open !== prev.open || st.error !== prev.error || st.mini !== prev.mini) {
|
||||
const html = document.documentElement.classList;
|
||||
html.toggle('video-active', st.open && st.firstFrame && !st.error);
|
||||
html.toggle('player-open', st.open && !st.mini);
|
||||
html.toggle('player-mini', st.open && st.mini);
|
||||
}
|
||||
});
|
||||
|
||||
/** Subtitle look changes apply to the playing video straight away. */
|
||||
const SUBTITLE_PREFS = ['subtitleScale', 'subtitleColor', 'subtitleEdge', 'subtitleBox', 'subtitleBold', 'subtitlePosition'] as const;
|
||||
useSettings.subscribe((prefs, prev) => {
|
||||
if (isNative && usePlayer.getState().open && SUBTITLE_PREFS.some((k) => prefs[k] !== prev[k])) applySubtitleStyle(prefs);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ function fadeTo(target: number, done?: () => void) {
|
|||
if (fade) clearInterval(fade);
|
||||
const a = audio;
|
||||
fade = setInterval(() => {
|
||||
const step = 0.02;
|
||||
const step = Math.max(0.002, target / 25, a.volume / 25);
|
||||
if (Math.abs(a.volume - target) <= step) {
|
||||
a.volume = target;
|
||||
clearInterval(fade!);
|
||||
|
|
@ -21,17 +21,27 @@ function fadeTo(target: number, done?: () => void) {
|
|||
}, 40);
|
||||
}
|
||||
|
||||
/**
|
||||
* Theme songs are mastered far louder than a film's dialogue, so the setting
|
||||
* follows a square law and scales with the player's own volume: the default
|
||||
* 30% sits around -21 dB, under the show it introduces.
|
||||
*/
|
||||
function themeGain() {
|
||||
const { themeVolume, volume } = useSettings.getState();
|
||||
return Math.pow(themeVolume / 100, 2) * Math.pow(Math.min(100, volume) / 100, 2);
|
||||
}
|
||||
|
||||
export function playThemeMusic(path: string) {
|
||||
const prefs = useSettings.getState();
|
||||
const server = useSession.getState().server;
|
||||
if (!prefs.themeMusic || !path || !server || document.documentElement.classList.contains('player-open')) return;
|
||||
if (!prefs.themeMusic || !path || !server || /player-(open|mini)/.test(document.documentElement.className)) return;
|
||||
if (path === current && audio && !audio.paused) return;
|
||||
stopThemeMusic(true);
|
||||
current = path;
|
||||
audio = new Audio(server.signed(path));
|
||||
audio.volume = 0;
|
||||
audio.loop = false;
|
||||
audio.play().then(() => fadeTo(prefs.themeVolume / 100), () => {});
|
||||
audio.play().then(() => fadeTo(themeGain()), () => {});
|
||||
}
|
||||
|
||||
export function stopThemeMusic(immediate = false) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue