2 Commits
Author SHA1 Message Date
CaZzzer 707ba4cdf2 player: pause in future 2026-04-15 13:30:26 -07:00
CaZzzer 1a20111501 player: mute by default to bypass autoplay restrictions 2026-04-15 13:29:45 -07:00
+7 -3
View File
@@ -45,8 +45,9 @@
const diff = Math.abs(el.currentTime - expectedTime); const diff = Math.abs(el.currentTime - expectedTime);
if (!state.isPlaying) { if (!state.isPlaying) {
if (el.currentTime < expectedTime && diff <= 2 && !el.paused) { if (el.currentTime < expectedTime && diff <= 2) {
// Behind pause point. Keep playing to catch up. (timeupdate will pause it) // Behind pause point. Keep playing to catch up. (timeupdate will pause it)
// If locally paused, stay paused (we likely dispatched the pause event + buffer)
} else { } else {
// Ahead or reached pause point. Pause and rewind if needed. // Ahead or reached pause point. Pause and rewind if needed.
syncAction(() => { syncAction(() => {
@@ -72,12 +73,14 @@
function handlePlay() { function handlePlay() {
if (isSyncing) return; if (isSyncing) return;
playReducer({ timePosition: videoElement?.currentTime ?? 0 }); // Send play slightly in future to adjust for network latency
playReducer({ timePosition: (videoElement?.currentTime ?? 0) + 0.15 });
} }
function handlePause() { function handlePause() {
if (isSyncing) return; if (isSyncing) return;
pauseReducer({ timePosition: videoElement?.currentTime ?? 0 }); // Send pause slightly in future, so remote clients coast into it
pauseReducer({ timePosition: (videoElement?.currentTime ?? 0) + 0.15 });
} }
function handleSeeked() { function handleSeeked() {
@@ -135,6 +138,7 @@
<!-- svelte-ignore a11y_media_has_caption --> <!-- svelte-ignore a11y_media_has_caption -->
<video <video
bind:this={videoElement} bind:this={videoElement}
muted
controls controls
onplay={handlePlay} onplay={handlePlay}
onpause={handlePause} onpause={handlePause}