Compare commits
2 Commits
acb0cd3161
...
707ba4cdf2
| Author | SHA1 | Date | |
|---|---|---|---|
|
707ba4cdf2
|
|||
|
1a20111501
|
@@ -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}
|
||||||
|
|||||||
Reference in New Issue
Block a user