Skip to content

Commit 318dbf0

Browse files
committed
fix(core): keep a looping video playing when the playhead wraps before it
1 parent 2c846ed commit 318dbf0

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

‎packages/core/src/runtime/media.test.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2039,6 +2039,19 @@ describe("syncRuntimeMedia", () => {
20392039
tick(clip, 9.99);
20402040
expect(el.play).not.toHaveBeenCalled();
20412041
});
2042+
2043+
it("keeps a looping video playing when the playhead wraps a lap before it", () => {
2044+
const clip = videoClip({ start: 0, end: 10, mediaStart: 0, loop: true, sourceDuration: 0.4 });
2045+
const el = clip.el;
2046+
Object.defineProperty(el, "paused", { value: false, writable: true, configurable: true });
2047+
el.pause = vi.fn();
2048+
for (let tickIndex = 0; tickIndex < 100; tickIndex++) {
2049+
const timeSeconds = 0.3 + tickIndex * 0.004;
2050+
el.currentTime = Math.min(timeSeconds, 0.39); // the element lags at the end of each lap
2051+
tick(clip, timeSeconds);
2052+
}
2053+
expect(el.pause).not.toHaveBeenCalled();
2054+
});
20422055
});
20432056

20442057
describe("playing media drift", () => {

‎packages/core/src/runtime/media.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -580,9 +580,10 @@ export function syncRuntimeMedia(params: {
580580
// strict and force sync and is steered by rate; hard sync (>0.5s) and audio past its steer
581581
// limit seek. A paused transport pauses it below, so a seek that pauses mid-playback lands it.
582582
if (el.tagName === "VIDEO" && !isHeldVideoTail) {
583+
// A loop's playhead wraps before its element, so its offset jumps by a lap: steering owns loops.
583584
const ahead =
584-
offset < -VIDEO_LEAD_HOLD_SECONDS ||
585-
(!clip.loop &&
585+
!clip.loop &&
586+
(offset < -VIDEO_LEAD_HOLD_SECONDS ||
586587
currentElTime >= mediaSourceTimeAt(clip, clip.end) - MEDIA_SYNC_TOLERANCE_SECONDS);
587588
if (!playing || (!ahead && offset >= -MEDIA_SYNC_TOLERANCE_SECONDS)) heldAhead.delete(el);
588589
else if (ahead && !el.paused) {

0 commit comments

Comments
 (0)