player: pause in future

This commit is contained in:
2026-04-15 13:30:26 -07:00
parent 1a20111501
commit 707ba4cdf2

View File

@@ -45,8 +45,9 @@
const diff = Math.abs(el.currentTime - expectedTime);
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)
// If locally paused, stay paused (we likely dispatched the pause event + buffer)
} else {
// Ahead or reached pause point. Pause and rewind if needed.
syncAction(() => {
@@ -72,12 +73,14 @@
function handlePlay() {
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() {
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() {